1. 程式人生 > WINDOWS開發 >WPF 通過Win32SDK修改視窗樣式

WPF 通過Win32SDK修改視窗樣式

原文:WPF 通過Win32SDK修改視窗樣式

使用函式為

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位請參考網頁的

GetWindowLongPtrASetWindowLongPtrA使用方法不變