WPF 通過Win32SDK修改視窗樣式
阿新 • • 發佈:2020-05-06
原文:WPF 通過Win32SDK修改視窗樣式
使用函式為
SetWindowLong
GetWindowLong
註冊函式
[DllImport("user32.dll",EntryPoint = "GetWindowLong")] public static extern int GetWindowLong(IntPtr hwnd,int nIndex); [DllImport("user32.dll",EntryPoint = "SetWindowLong")] public staticextern 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使用方法不變