問題描述
我必須在第三方庫中隱藏彈出窗口.
I have to hide popup windows in third party library.
我已經使用 SetWindowsHookEx 實現了 Windows 掛鉤內容a> 并知道所有新創建的 hWnd(s).我聽 HSHELL_WINDOWCREATED
回調并執行以下操作:
I have implemented windows hook stuff with SetWindowsHookEx and know all the newely created hWnd(s). I listen to HSHELL_WINDOWCREATED
callback and do the following:
long style= GetWindowLong(hWnd, GWL_STYLE);
style &= ~(WS_VISIBLE); // this works - window become invisible
style |= WS_EX_TOOLWINDOW; // flags don't work - windows remains in taskbar
style &= ~(WS_EX_APPWINDOW);
SetWindowLong(hWnd, GWL_STYLE, style);
在任務欄中隱藏新創建的窗口我做錯了什么?
What I do wrong here to hide newely created windows in task bar?
推薦答案
在使用SetWindowLong
之前,先調用ShowWindow(hWnd, SW_HIDE)
,然后再調用SetWindowLong
,然后像 ShowWindow(hWnd, SW_SHOW)
一樣再次調用 ShowWindow
.所以你的代碼看起來像這樣:
Before you use SetWindowLong
, call ShowWindow(hWnd, SW_HIDE)
, then call SetWindowLong
, then call ShowWindow
again like ShowWindow(hWnd, SW_SHOW)
. So your code will look like this:
long style= GetWindowLong(hWnd, GWL_STYLE);
style &= ~(WS_VISIBLE); // this works - window become invisible
style |= WS_EX_TOOLWINDOW; // flags don't work - windows remains in taskbar
style &= ~(WS_EX_APPWINDOW);
ShowWindow(hWnd, SW_HIDE); // hide the window
SetWindowLong(hWnd, GWL_STYLE, style); // set the style
ShowWindow(hWnd, SW_SHOW); // show the window for the new style to come into effect
ShowWindow(hWnd, SW_HIDE); // hide the window so we can't see it
這是來自 微軟網站的相關引述:
為了防止窗口按鈕被放置在任務欄上,創建具有 WS_EX_TOOLWINDOW 擴展樣式的無主窗口.作為替代方案,您可以創建一個隱藏窗口并將其隱藏window 可見窗口的所有者.
To prevent the window button from being placed on the taskbar, create the unowned window with the WS_EX_TOOLWINDOW extended style. As an alternative, you can create a hidden window and make this hidden window the owner of your visible window.
Shell 只會在以下情況下從任務欄中刪除窗口按鈕窗口的樣式支持可見的任務欄按鈕.如果你想將窗口的樣式動態更改為不支持的樣式可見的任務欄按鈕,您必須先隱藏窗口(通過調用ShowWindow with SW_HIDE),更改窗口樣式,然后顯示窗口.
The Shell will remove a window's button from the taskbar only if the window's style supports visible taskbar buttons. If you want to dynamically change a window's style to one that doesn't support visible taskbar buttons, you must hide the window first (by calling ShowWindow with SW_HIDE), change the window style, and then show the window.
這篇關于Win32:如何通過 hWnd 在任務欄中隱藏 3rd 方窗口的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!