使用函数为
- SetWindowLong
- GetWindowLong
注册函数
- [DllImport("user32.dll", EntryPoint = "GetWindowLong")]
- public static extern int GetWindowLong(IntPtr hwnd, int nIndex);
- [DllImport("user32.dll", EntryPoint = "SetWindowLong")]
- public static extern int SetWindowLong(IntPtr hMenu, int nIndex, int dwNewLong);
使用函数
- private void DisableSizebox()
- {
- int GWL_STYLE = -16;
- int WS_THICKFRAME = 0x00040000;
- IntPtr handle = new WindowInteropHelper(this).Handle;
- int nStyle = GetWindowLong(handle, GWL_STYLE);
- // 禁用调整窗口大小
- nStyle &= ~WS_THICKFRAME;
- SetWindowLong(handle, GWL_STYLE,nStyle);
- }
注意 启用窗口样式为
nStyle|=WS_THICKFRAME
如果是多个样式启用或者禁止为
- // 禁用
- nStyle &= ~WS_CAPTION&~WS_MINIMIZEBOX;
- // 启用
- nStyle |= WS_MAXIMIZEBOX| WS_CAPTION;
具体样式请参考具体 Windows Style
注意: msdn 中均为 Long 型, 去掉 L 即可为 int,
本函数均为 32 位, 对应 64 位请参考网页的 GetWindowLongPtrA,SetWindowLongPtrA 使用方法不变
来源: http://www.bubuko.com/infodetail-3536451.html