Ejemplo n.º 1
0
        void SubClassingWin32()
        {
            MauiWinUIApplication.Current.Services?.InvokeLifecycleEvents <WindowsLifecycle.OnPlatformWindowSubclassed>(
                del => del(this, new WindowsPlatformWindowSubclassedEventArgs(WindowHandle)));

            newWndProc = new PlatformMethods.WindowProc(NewWindowProc);
            oldWndProc = PlatformMethods.SetWindowLongPtr(WindowHandle, PlatformMethods.WindowLongFlags.GWL_WNDPROC, newWndProc);

            IntPtr NewWindowProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
            {
                if (msg == WindowsPlatformMessageIds.WM_SETTINGCHANGE || msg == WindowsPlatformMessageIds.WM_THEMECHANGE)
                {
                    MauiWinUIApplication.Current.Application?.ThemeChanged();
                }

                if (msg == WindowsPlatformMessageIds.WM_DPICHANGED)
                {
                    var dpiX = (short)(long)wParam;
                    var dpiY = (short)((long)wParam >> 16);

                    var window = this.GetWindow();
                    if (window is not null)
                    {
                        window.DisplayDensityChanged(dpiX / DeviceDisplay.BaseLogicalDpi);
                    }
                }

                MauiWinUIApplication.Current.Services?.InvokeLifecycleEvents <WindowsLifecycle.OnPlatformMessage>(
                    m => m.Invoke(this, new WindowsPlatformMessageEventArgs(hWnd, msg, wParam, lParam)));

                return(PlatformMethods.CallWindowProc(oldWndProc, hWnd, msg, wParam, lParam));
            }
        }
Ejemplo n.º 2
0
        void SubClassingWin32()
        {
            MauiWinUIApplication.Current.Services?.InvokeLifecycleEvents <WindowsLifecycle.OnPlatformWindowSubclassed>(
                del => del(this, new WindowsPlatformWindowSubclassedEventArgs(WindowHandle)));

            newWndProc = new PlatformMethods.WindowProc(NewWindowProc);
            oldWndProc = PlatformMethods.SetWindowLongPtr(WindowHandle, PlatformMethods.WindowLongFlags.GWL_WNDPROC, newWndProc);

            IntPtr NewWindowProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
            {
                if (msg == WindowsPlatformMessageIds.WM_SETTINGCHANGE || msg == WindowsPlatformMessageIds.WM_THEMECHANGE)
                {
                    MauiWinUIApplication.Current.Application?.ThemeChanged();
                }

                MauiWinUIApplication.Current.Services?.InvokeLifecycleEvents <WindowsLifecycle.OnPlatformMessage>(
                    m => m.Invoke(this, new WindowsPlatformMessageEventArgs(hWnd, msg, wParam, lParam)));

                return(PlatformMethods.CallWindowProc(oldWndProc, hWnd, msg, wParam, lParam));
            }
        }