private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            switch (msg)
            {
            case 126:
                if (IsVisible)
                {
                    RenderLayeredWindow();
                }
                break;

            case 33:
                handled = true;
                return(new IntPtr(3));

            case 132:
                Cursor = GetCursor(lParam) ?? Cursors.None;
                break;

            case 161:
            case 163:
            case 164:
            case 166:
            case 167:
            case 169:
            case 171:
            case 173:
                var targetWindowHandle = TargetWindowHandle;
                NativeMethods.SendMessage(targetWindowHandle, 6, new IntPtr(2), IntPtr.Zero);
                NativeMethods.SendMessage(targetWindowHandle, msg, wParam, IntPtr.Zero);
                break;

            case 6:
                return(IntPtr.Zero);

            case 70:
                var windowPos = (Windowpos)Marshal.PtrToStructure(lParam, typeof(Windowpos));
                windowPos.flags |= 16U;
                Marshal.StructureToPtr(windowPos, lParam, true);
                break;

            case 513:
                if (!IsHitTestVisible)
                {
                    break;
                }
                var pt = new Point((int)lParam & 0xFFFF, ((int)lParam >> 16) & 0xFFFF);
                NativeMethods.PostMessage(TargetWindowHandle,
                                          161, (IntPtr)DecideResizeDirection(pt),
                                          IntPtr.Zero);
                break;
            }
            return(NativeMethods.DefWindowProc(hwnd, msg, wParam, lParam));
        }
        protected static void ShowWindowMenu(HwndSource source, Point screenPoint, bool canMinimize)
        {
            var systemMetrics   = NativeMethods.GetSystemMetrics(40);
            var systemMenu      = NativeMethods.GetSystemMenu(source.Handle, false);
            var windowPlacement = NativeMethods.GetWindowPlacement(source.Handle);
            var flag            = VisualUtilities.ModifyStyle(source.Handle, 268435456, 0);
            var uEnable         = canMinimize ? 0U : 1U;

            if (windowPlacement.showCmd == 1)
            {
                NativeMethods.EnableMenuItem(systemMenu, 61728U, 1U);
                NativeMethods.EnableMenuItem(systemMenu, 61456U, 0U);
                NativeMethods.EnableMenuItem(systemMenu, 61440U, 0U);
                NativeMethods.EnableMenuItem(systemMenu, 61488U, 0U);
                NativeMethods.EnableMenuItem(systemMenu, 61472U, uEnable);
                NativeMethods.EnableMenuItem(systemMenu, 61536U, 0U);
            }
            else if (windowPlacement.showCmd == 3)
            {
                NativeMethods.EnableMenuItem(systemMenu, 61728U, 0U);
                NativeMethods.EnableMenuItem(systemMenu, 61456U, 1U);
                NativeMethods.EnableMenuItem(systemMenu, 61440U, 1U);
                NativeMethods.EnableMenuItem(systemMenu, 61488U, 1U);
                NativeMethods.EnableMenuItem(systemMenu, 61472U, uEnable);
                NativeMethods.EnableMenuItem(systemMenu, 61536U, 0U);
            }
            if (flag)
            {
                VisualUtilities.ModifyStyle(source.Handle, 0, 268435456);
            }
            var fuFlags = (uint)(systemMetrics | 256 | 128 | 2);
            var num     = NativeMethods.TrackPopupMenuEx(systemMenu, fuFlags, (int)screenPoint.X, (int)screenPoint.Y,
                                                         source.Handle, IntPtr.Zero);

            if (num == 0)
            {
                return;
            }
            NativeMethods.PostMessage(source.Handle, 274, new IntPtr(num), IntPtr.Zero);
        }