博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
wpf 自定义 无边框 窗体 resize 实现
阅读量:7251 次
发布时间:2019-06-29

本文共 2325 字,大约阅读时间需要 7 分钟。

 参数定义

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                 //bottom12                 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                 //Right21                 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                 //HTBOTTOMRIGHT31                 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         }

 

转载于:https://www.cnblogs.com/ParkWu/p/5537128.html

你可能感兴趣的文章
网站接入微信扫码登录并获取用户基本信息(微信开放平台)
查看>>
HTC VIVE Wave 概览
查看>>
Vue动态控制input的disabled属性
查看>>
TCP的局限性有哪些?
查看>>
【前端数据结构基础】栈
查看>>
沙漠种水稻,88岁的袁隆平又创造奇迹!他参与的“袁米”还有个大计划
查看>>
JS基础入门篇(二十四)—DOM(上)
查看>>
阿里架构师眼里JVM可以说的那些事
查看>>
如何将应用完美迁移至Android P版本
查看>>
对数据科学家来说最重要的算法和统计模型
查看>>
Angular4 反向代理Details
查看>>
AngularJS 过滤器
查看>>
【Ubuntu17.10】【Python】菜鸟新建文件夹、给予777权限、新建一个简单的python脚本测试...
查看>>
2018 浅谈前端面试那些事
查看>>
flutter实战3:解析HTTP请求数据和制作新闻分类列表
查看>>
react onCompositionStart/Update/onCompositionStartEnd 触发时机
查看>>
一个强大的批处理文件
查看>>
基于 Swoole 的微信扫码登录
查看>>
Largest Rectangle in Histogram
查看>>
聊聊pg jdbc的queryTimeout及next方法
查看>>