Want to display or hide a window in the VB is easy to set a Form's showintabkbar property directly on the taskbar. But in the SDK is not a matter, one window will display a button on the taskbar in the case, in what circumstances not displayed? This is specified:
0, no matter what situation, let a window show the button on the taskbar is that the window is visible.
1. If a window is a top window (that is, the parent window is null, that is, the parent window is a desktop window), then Windows will create a button for it on the taskbar. (There are exceptions, see 3)
2. If a window is not a top window, there is a WS_EX_APPWindow style, then Windows will create a button for it on the taskbar, otherwise there will be no corresponding taskbar buttons.
3. If a window is a top window, add WS_EX_TOOLWINDOW, and remove the WS_EX_APPWindow style, then Windows will not create a button for it on the taskbar.
4 ....
I know these rules, you can control your window if you want to control your window, and give a problem and solution.
Question: A dialog-based project in the MFC, want the primary dialog box not displaying buttons on the taskbar, how to do it?
Solution 1:
The third rule above the roots, adds the WS_EX_TOOLWINDOW style and removes the WS_EX_APPWindow style.
Code:
Add: ModifyStyleex (WS_EX_APPWINDOW, SWP_FRAMECHANGED); MODIFYSTYLEEX;
Remarks: This method will have a shortcomings that your dialog box will be a small title, so most people will not use this method.
Solution 2:
The second rule above the roots, turning the dialog to a non-top window and removes WS_EX_APPWindow, generate a hidden dialog in the main dialog Domodal in the INITINSTANCE of the App class, and save the pointer of this window in CWINAPP In the M_PMainWnd member variable of the class, the Domodal dialog box will be its sub-window.
Code:
Add the following quasi-code () {... cframeWnd mainwnd; // generate a frame window object mainwnd.create (NULL, "aa"); // Generate Window, not With ws_visible, that is, it will not be displayed.
CTestDLGDLG DLG; m_pmainwnd = & mainwnd; // Set this hidden window as the main window
INT nresponse = dlg.domodal (); ...}
Add ModifyStyleex (WS_EX_APPWINDOW, 0) in the OnInitDialog in the dialog; in order to go out of WS_EX_AppWindow.
Remarks: This method is more troublesome, but it is very practical. According to my observation, the program generated by C Builder and Delphi should have a hidden window.
Solution 3:
There is a interface called iTaskbarlist in the system of the IE version of 4.0 or more. This interface can be used to control whether the button on the taskbar is displayed. Just give the handle of a window and whether it is displayed, do not need to consider The above is chaotic rules.
Code:
void ShowInTaskbar (HWND m_hWnd, BOOL bshow) {// added in InitInstance app :: CoInitialize (NULL); HRESULT hr; ITaskbarList * pTaskbarList; hr = CoCreateInstance (CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList, (void **) & pTaskbarList ); Ptaskbarlist-> hrinit (); // MSDN said that this method is called before using this interface to do some initialization action, I found that it is not called. If (bshow) {ptaskbarlist-> Addtab (m_hwnd);} else {ptaskbarlist-> deleteTab (m_hwnd);} ptaskbarlist-> release (); // Add :: Couninitialize () in an app
}
Calling this function when needed, the first parameter is the handle of the window, the second parameter indicates whether the button is displayed on the taskbar.
Remarks: This method is powerful, and the use is also simpler, but the low version of Windows may not be supported.
All three programs can be selected according to the situation.