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

本文共 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

你可能感兴趣的文章
解决Centos/Redhat,命令不存在
查看>>
项目实战—小饭桌
查看>>
彻底弄懂js循环中的闭包问题
查看>>
python测试开发django-24.表单提交之get请求
查看>>
帧动画布局文件 animation-list
查看>>
zoj 3165 (最小割,最大点权独立集)
查看>>
ArrayList深拷贝的一种实现方法
查看>>
2012考研英语--前辈的高分复习经验
查看>>
UVA10603倒水问题+隐式图搜索
查看>>
C++学习之字符串
查看>>
图像化列表
查看>>
2014年10月9日——语言基础2
查看>>
mysql查
查看>>
[正则表达式]难点和误区
查看>>
217. Contains Duplicate
查看>>
hadoop遇到问题总结
查看>>
Windows下手动安装redis服务
查看>>
把 MongoDB 当成是纯内存数据库来使用(Redis 风格)
查看>>
PyTorch 1.0 中文官方教程:使用ONNX将模型从PyTorch传输到Caffe2和移动端
查看>>
LeetCode 4Sum
查看>>