コード例 #1
0
        private static void SplashThreadProcedure()
        {
            bool isOK = true;
            MSG  message;

            if (SplashScreen.splashWindowProcedure == null)
            {
                isOK = SplashScreen.current.RegisterWindowClass();
            }

            if (isOK)
            {
                isOK = SplashScreen.current.CreateNativeWindow();
            }

            if (isOK)
            {
                message = new MSG();

                while (APIMessage.GetMessage(ref message, IntPtr.Zero, 0, 0))
                {
                    APIMessage.TranslateMessage(ref message);
                    APIMessage.DispatchMessage(ref message);
                }

                SplashScreen.current._hwnd = IntPtr.Zero;

                if (SplashScreen.current._windowToActivate != null)
                {
                    if (SplashScreen.current._handleToActivate != IntPtr.Zero)
                    {
                        SplashScreen.Current._windowToActivate = null;
                        APIWindow.SetForegroundWindow(APIWindow.GetLastActivePopup(SplashScreen.current._handleToActivate));
                        APIPainting.RedrawWindow(SplashScreen.current._handleToActivate, IntPtr.Zero, IntPtr.Zero, (uint)0x85);
                        SplashScreen.current._handleToActivate = IntPtr.Zero;
                    }
                }
            }
        }
コード例 #2
0
        private bool RegisterWindowClass()
        {
            bool     registerSuccess;
            WNDCLASS wndClass;

            SplashScreen.splashWindowProcedure = new WNDPROC(SplashWindowProcedure);

            registerSuccess = false;
            wndClass        = new WNDCLASS();

            wndClass.style         = (int)((int)ClassStylesFlags.CS_VREDRAW | (int)ClassStylesFlags.CS_HREDRAW);
            wndClass.hInstance     = APIDynamicLinkLibrary.GetModuleHandle(null);          //(IntPtr) 0;
            wndClass.hIcon         = (IntPtr)0;
            wndClass.hCursor       = (IntPtr)0;
            wndClass.hbrBackground = ((IntPtr)SystemColorsIndex.COLOR_WINDOWFRAME);
            wndClass.lpszMenuName  = "";
            wndClass.cbClsExtra    = 0;
            wndClass.cbWndExtra    = 0;
            wndClass.lpfnWndProc   = SplashScreen.splashWindowProcedure;
            wndClass.lpszClassName = WindowClassName;


            if (this._showShadow && this.IsDropShadowSupported())
            {
                wndClass.style = (wndClass.style | (int)WindowClassStyles.CS_DROPSHADOW);
            }
            else
            {
                wndClass.style &= ~((int)WindowClassStyles.CS_DROPSHADOW);
            }

            if (APIWindow.RegisterClass(ref wndClass) != IntPtr.Zero)
            {
                registerSuccess = true;
            }

            return(registerSuccess);
        }
コード例 #3
0
        private bool CreateNativeWindow()
        {
            bool      isCreated = false;
            uint      windowStyle;
            uint      windowStyleEx;
            Screen    screen;
            Rectangle rectangle;

            windowStyle   = (uint)WindowStyles.WS_POPUP | (uint)WindowStyles.WS_VISIBLE;
            windowStyleEx = (uint)WindowStylesEx.WS_EX_TOPMOST | (uint)WindowStylesEx.WS_EX_TOOLWINDOW;

            if (!this._transparencyKey.IsEmpty && this.IsLayeringSupported())
            {
                windowStyleEx = (windowStyleEx | (uint)WindowStylesEx.WS_EX_LAYERED);                  // 524288
            }

            screen    = Screen.FromPoint(Control.MousePosition);
            rectangle = screen.WorkingArea;

            int posX = Math.Max(rectangle.X, (rectangle.X + ((rectangle.Width - this._width) / 2)));
            int posY = Math.Max(rectangle.Y, (rectangle.Y + ((rectangle.Height - this._height) / 2)));

            this._hwnd = APIWindow.CreateWindowEx(windowStyleEx, WindowClassName, "", (uint)windowStyle, posX, posY, this._width, this._height, IntPtr.Zero, IntPtr.Zero, APIDynamicLinkLibrary.GetModuleHandle(null), IntPtr.Zero);

            if (this._hwnd != IntPtr.Zero)
            {
                APIWindow.ShowWindow(this._hwnd, 1);
                APIWindow.UpdateWindow(this._hwnd);
                isCreated = true;
            }
            else
            {
                System.Console.WriteLine("Cannot create window. {0}", APIError.FormatMessage(APIError.GetLastError()));
            }

            return(isCreated);
        }
コード例 #4
0
        private int SplashWindowProcedure(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam)
        {
            PAINTSTRUCT paintStruct;
            IntPtr      timerPtr;
            Graphics    graphics;

            if (msg <= (int)WindowMessages.WM_PAINT)
            {
                switch (msg)
                {
                case (int)WindowMessages.WM_CREATE:
                {
                    if (!this._transparencyKey.IsEmpty && this.IsLayeringSupported())
                    {
                        APIWindow.SetLayeredWindowAttributes(hwnd, (ulong)ColorTranslator.ToWin32(this._transparencyKey), (byte)0, LayeredWindowAttributesFlags.LWA_COLORKEY);
                    }

                    if (this._minimumDuration <= 0)
                    {
                        return(APIWindow.DefWindowProc(hwnd, msg, wParam, lParam));
                    }

                    this._timer = APITimer.SetTimer(hwnd, 1, this._minimumDuration, (TIMERPROC)null);
                    return(APIWindow.DefWindowProc(hwnd, msg, wParam, lParam));
                }

                case (int)WindowMessages.WM_DESTROY:
                {
                    APIMessage.PostQuitMessage(0);
                    return(APIWindow.DefWindowProc(hwnd, msg, wParam, lParam));
                }
                }

                if (msg == (int)WindowMessages.WM_PAINT)
                {
                    paintStruct = new PAINTSTRUCT();
                    timerPtr    = APIPainting.BeginPaint(hwnd, ref paintStruct);

                    if (timerPtr != IntPtr.Zero)
                    {
                        graphics = Graphics.FromHdcInternal(timerPtr);
                        graphics.DrawImage(this._image, 0, 0, this._width, this._height);

                        OnScreenCustomize(graphics);

                        graphics.Dispose();
                    }

                    APIPainting.EndPaint(hwnd, ref paintStruct);
                    return(0);
                }

                return(APIWindow.DefWindowProc(hwnd, msg, wParam, lParam));
            }

            if (msg == (int)WindowMessages.WM_ERASEBKGND)
            {
                return(1);
            }

            if (msg == (int)WindowMessages.WM_TIMER)
            {
                APITimer.KillTimer(hwnd, this._timer);
                this._timer = 0;
                this._minimumDurationComplete = true;

                if (this._waitingForTimer)
                {
                    APIMessage.PostMessage(hwnd, (int)WindowMessages.WM_CLOSE, (uint)IntPtr.Zero, (uint)IntPtr.Zero);
                }

                return(0);
            }

            return(APIWindow.DefWindowProc(hwnd, msg, wParam, lParam));
        }