예제 #1
0
        static Gdip()
        {
            ulong token  = 0;
            var   input  = GdiplusStartupInput.MakeGdiplusStartupInput();
            var   output = GdiplusStartupOutput.MakeGdiplusStartupOutput();

            GdiplusStartup(ref token, ref input, ref output);
        }
예제 #2
0
            internal static GdiplusStartupInput MakeGdiplusStartupInput()
            {
                GdiplusStartupInput result = new GdiplusStartupInput();

                result.GdiplusVersion           = 1;
                result.DebugEventCallback       = IntPtr.Zero;
                result.SuppressBackgroundThread = 0;
                result.SuppressExternalCodecs   = 0;
                return(result);
            }
예제 #3
0
 internal static extern int GdiplusStartup(ref ulong handle, ref GdiplusStartupInput startup, IntPtr zero);
예제 #4
0
 public static extern Status GdiplusStartup(ref ulong token, ref GdiplusStartupInput input, ref GdiplusStartupOutput output);
예제 #5
0
        public static void Main(string[] args)
        {
            try
            {
                var hInstance = Process.GetCurrentProcess().Handle;

                using var marshal = new StringToIntPtrMarshaler(WindowClass);
                var wndclass = new WNDCLASSEX
                {
                    cbSize        = (uint)Marshal.SizeOf(typeof(WNDCLASSEX)),
                    style         = ClassStyles.CS_DBLCLKS,
                    lpfnWndProc   = WindowProc,
                    cbClsExtra    = 0,
                    cbWndExtra    = 0,
                    hInstance     = hInstance,
                    hIcon         = LoadIcon(hInstance, SystemIcons.IDI_APPLICATION),
                    hCursor       = LoadCursor(IntPtr.Zero, SystemCursors.IDC_ARROW),
                    hbrBackground = (IntPtr)BackgroundColors.COLOR_WINDOW,
                    lpszMenuName  = IntPtr.Zero,
                    lpszClassName = marshal.GetPtr(),
                };

                if (RegisterClassEx(ref wndclass) != 0)
                {
                    _window = CreateWindowEx(WindowStylesEx.WS_EX_LAYERED, WindowClass, WindowName, WindowStyles.WS_OVERLAPPED, CW_USEDEFAULT, CW_USEDEFAULT,
                                             CW_USEDEFAULT, CW_USEDEFAULT, IntPtr.Zero, IntPtr.Zero, hInstance, IntPtr.Zero);
                    if (_window != IntPtr.Zero)
                    {
                        _windowDC = GetDC(_window);

                        SetPositionAndSize();
                        ShowWindow(_window, ShowWindowCommands.SW_SHOWNORMAL);

                        var startupInput = new GdiplusStartupInput
                        {
                            GdiplusVersion           = 1,
                            DebugEventCallback       = IntPtr.Zero,
                            SuppressBackgroundThread = false,
                            SuppressExternalCodecs   = false,
                        };
                        if (GdiplusStartup(out _gdipToken, ref startupInput, out _) == GpStatus.Ok && GdipLoadImageFromFile(SplashFile, out _splashImage) == GpStatus.Ok)
                        {
                            DrawImage();
                            while (GetMessage(out var msg, IntPtr.Zero, 0, 0) != 0)
                            {
                                try
                                {
                                    TranslateMessage(ref msg);
                                    DispatchMessage(ref msg);
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                            }
                        }
                        else
                        {
                            //TODO: throw GDI+ Error
                        }
                    }
                    else
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error());
                    }
                }
                else
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
            }
            finally
            {
                ReleaseAllResource();
            }
        }