• wpf 自定义 无边框 窗体 resize 实现


     参数定义

     1         class NativeMethods
     2         {
     3             public const int WM_NCHITTEST = 0x84;
     4             public const int HTCAPTION = 2;
     5             public const int HTLEFT = 10;
     6             public const int HTRIGHT = 11;
     7             public const int HTTOP = 12;
     8             public const int HTTOPLEFT = 13;
     9             public const int HTTOPRIGHT = 14;
    10             public const int HTBOTTOM = 15;
    11             public const int HTBOTTOMLEFT = 16;
    12             public const int HTBOTTOMRIGHT = 17;
    13         }

    加hook

    1 IntPtr windowHandle = new WindowInteropHelper(win).Handle;
    2  HwndSource windowSource = HwndSource.FromHwnd(windowHandle);
    3 windowSource.RemoveHook(WndProc);   
     1  private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
     2         {
     3             int GripSize = 16;
     4             int BorderSize = 7;
     5             Window win = (Window)System.Windows.Interop.HwndSource.FromHwnd(hwnd).RootVisual;
     6             if (msg == NativeMethods.WM_NCHITTEST)
     7             {
     8                 int x = lParam.ToInt32() << 16 >> 16, y = lParam.ToInt32() >> 16;
     9                 Point pos = win.PointFromScreen(new Point(x, y));
    10 
    11                 //bottom
    12                 if (pos.X > GripSize &&
    13                     pos.X < win.ActualWidth - GripSize &&
    14                     pos.Y >= win.ActualHeight - BorderSize)
    15                 {
    16                     handled = true;
    17                     return (IntPtr)NativeMethods.HTBOTTOM;
    18                 }
    19 
    20                 //Right
    21                 if (pos.Y > GripSize &&
    22                     pos.X > win.ActualWidth - BorderSize &&
    23                     pos.Y < win.ActualHeight - GripSize)
    24                 {
    25                     handled = true;
    26                     return (IntPtr)NativeMethods.HTRIGHT;
    27                 }
    28 
    29                 // Top, Left, Right, Corners, Etc.
    30                 //HTBOTTOMRIGHT
    31                 if (pos.X > win.ActualWidth - GripSize &&
    32                    pos.Y >= win.ActualHeight - GripSize)
    33                 {
    34                     handled = true;
    35                     return (IntPtr)NativeMethods.HTBOTTOMRIGHT;
    36                 }
    37             }
    38 
    39             return IntPtr.Zero;
    40         }
  • 相关阅读:
    ubuntu常用快捷键,不断更新中~
    C语言模拟漏斗
    浅谈webCam
    1001. A+B Format
    点、边、面——欧拉公式
    果园里的树
    生产计划
    Stanford Machine Learning 学习 2016/7/4
    paper reading
    paper reading in this week
  • 原文地址:https://www.cnblogs.com/ParkWu/p/5537128.html
Copyright © 2020-2023  润新知