使用函数为
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使用方法不变