Several ways to hide application buttons in the Windows task bar(隐藏Windows任务栏中的应用程序按钮的几种方法)
Several ways to hide application buttons in the Windows task
bar(隐藏Windows任务栏中的应用程序按钮的几种方法)
Describes how to hide application buttons in the Windows taskbar
Abstract: This paper introduces several methods of the author in the practice of hiding applications in the taskbar button, and a detailed analysis of each one of the methods, advantages and disadvantages of each method. The main source section of each method will be provided in this article.
Keywords: Windows taskbar, Windows task list, COM
First, the question raised
First of all, programming under the Windows programmer knows, when an application is created after will join an application in the Windows taskbar button in the Windows task list (i.e. list by Ctrl+Alt+Del after the addition of the application's title), Windows will be added according to the application information list after Alt+Tab in. The information about the operation of Windows users is quite useful, users can use the mouse and keyboard in various applications for advanced users can also switch by pressing the Ctrl+Alt+Del to terminate one application. However, in the design process, programmers sometimes hope to create one in the taskbar (even in the task list and the list by Alt+Tal in) no application on program information, such as the "golden eye" program. The author encountered this problem in his work. The following is a summary of the author's solution to the problem.
Two. Hide the application button in the taskbar
It should be said that this method is a relatively formal solution to the problem so far. This method is more detailed in MSDN,. Readers can get the following entries in MSDN by indexing the keyword "Talkbar": Modifying, the, Contents, of, the, Taskbar. The following is the Chinese translation of this article:
Microsoft Internet Explorer 4 adds the ability to change the contents of the taskbar. You can add, delete, and activate a button in an application in an application. Activating a button can not activate the corresponding window at the same time; it simply presses the button down".
The taskbar is changed. Yes, the executor is a OLE COM object. This object is created by calling CoCreateInstance () using the CLSID_TaskbarList parameter. This interface object you need is IDD_ITaskbarList. This creates an object and returns a pointer to the ITaskbarList interface. You must call the ITaskbarList:: HrInit method to initialize the object. If the HrInit () method calls successfully, you will be able to change the contents of the task bar using the method in the ITaskbarList interface.
We delete the application button in the taskbar, as provided in the MSDN document.
First, we must declare a ITaskbarList object:
DECLARE_INTERFACE_ (ITaskbarList, IUnknown)
{
STDMETHOD (QueryInterface) (THIS_, REFIID, riid, LPVOID * ppvObj) PURE;
STDMETHOD_ (ULONG, AddRef) (THIS) PURE;
STDMETHOD_ (ULONG, Release) (THIS) PURE;
STDMETHOD (ActivateTab) (HWND) PURE;
STDMETHOD (AddTab) (HWND) PURE;
STDMETHOD (DeleteTab) (HWND) PURE;
STDMETHOD (HrInit) (HWND) PURE;
};
Typedef ITaskbarList *LPITaskbarList;
Then, you need to remove the application's buttons in the taskbar and add the following code:
LPITaskbarList pTaskbar = NULL;
CoInitialize (0);
CoCreateInstance (CLSID_TaskbarList, 0, CLSCTX_INPROC_SERVER,
IID_ITaskbarList, (void * *) &pTaskbar);
PTaskbar->HrInit (hWnd); //hWnd is the handle to the application's main window
PTaskbar->DeleteTab (hWnd); //hWnd is the handle to the application's main window
If you want to remove the button immediately after running the program, in the MFC application can be the code to the main application window (OnPaint) method; in the SDK application can be more than WinMain () function code is added to the message loop before. It should be said that this method provided by Microsoft official will work, but this method has a lot of defects, that is when the application window is the taskbar any part (including the start menu) to cover after reactivation when the application button is. This is why in the MFC application to DeleteTab (hWnd) on the OnPaint () method in reason, if placed in the OnCreate () method even though in OnCreate () when the button is removed, but in the OnCreate () after the operation process in the button again. Microsoft also provides a way to get rid of the application buttons on the taskbar, which are the second methods to be introduced.
Three, hide the taskbar in the application button second methods
When you create a window with the CreateEx () method, you can set the extended attributes of the window. In MSDN, the explanation for this property is:
Create a tool window that will be deliberately created as a
floating toolbar style. The title bar of a tool window is narrower than the title bar of the general window, and a smaller font is used in the title bar. The tools window will not appear on the taskbar, and will not appear after pressing ALT+TAB."
Based on the above principle, we can easily create a so-called tool window. When you use MFC, you can only add the following code in the PreCreateWindow () method of the application main window:
Cs.dwExStyle WS_EX_TOOLWINDOW |=;
When using SDK, simply use the CreateEx () method when creating the main window and add WS_EX_TOOLWINDOW to the extended property.
In comparison with the first approach, the implementation of this approach is fairly simple, and there is no flaw in the first approach. However, this method still has some shortcomings, first of all, because of the narrow window is a tool window title bar looks not very good; secondly, when using a MFC based on the dialog box procedure is simply the main dialog box for Tool window and cannot implement the tool window.
Four, hide the taskbar in the application button third methods
Before introducing the third method, let's first analyze what kind of application will appear in the taskbar button, according to the MSDN document, when an application has the following characteristics:
1, it is not a window of the system, that is, the so-called owned window;
2, it is the main window of the application;
3, the window is non hidden window, not using ShowWindow (WS_HIDE) display.
There are more than three features of applications will appear in the taskbar button, if so, then we are not possible by creating a tool window first and then use it to create your own window. For that reason, the author set up a dialog based MFC project (engineering name Test) and made the following modifications in the InitInstance () method:
CFrameWnd* pFrame = new CFrameWnd;
M_pMainWnd = pFrame;
PFrame->Create (NULL, _T ("")); / / create a new frame and the main frame to the frame
CTestDlg dlg;
/ / m_pMainWnd = &dlg; / / delete the main frame to the main dialog box statement
Int nResponse = dlg.DoModal ();
If (nResponse = IDOK)
{}
Else if (nResponse = IDCANCEL)
{}
Return FALSE;
When you run this program, the application button in the taskbar is gone, but there is still an icon that represents the program after pressing Alt+Tab.
So, to improve, hide the m_pMainWnd's parent window, and change the program to:
LPCTSTR TestClass = AfxRegisterWndClass (0);
CWnd wndTest;
WndTest.CreateEx (WS_EX_TOOLWINDOW, TestClass,),
WS_OVERLAPPED,
0,0,0,0, NULL, 0); / / create a tool window as the main frame of the parent window
CFrameWnd* pFrame = new CFrameWnd;
M_pMainWnd = pFrame; / / framework will point to their own definition of the main frame
/ / create the main frame
PFrame->Create (NULL, _T ()), WS_OVERLAPPED, CRect (0,0,0,0), &wndTest);
CTestDlg dlg;
Int nResponse = dlg.DoModal ();
If (nResponse = IDOK)
{}
Else if (nResponse = IDCANCEL)
{}
Return FALSE;
Thus, the created application will not appear in the taskbar without buttons and will not appear after pressing Alt+Tab. If you want to create MFC programs based on other types, you can change the parent window of the main frame in the
PreCreateWindow () method of the main frame.
Five, hide the taskbar in the application button fourth methods
This method is more complex, taking into account the use of the "hook" can change the message flow, therefore, I think we can send messages by intercepting system taskbar to stop the application button in the taskbar. Because this method is more complex, and the above has a very concise method, the author
did not make further research on the method. Interested readers can try it on their own.
Six, remove the display of the application in the task list
We all know that in the press Ctrl+Alt+Tal after the system list will be listed in the running program, so even if we were trying to hide the program on the taskbar button, the user can still be an easy job to do our program termination. The following author provides ways to get rid of the application in the task list:
Typedef DWORD (WINAPI, Fun) (DWORD, DWORD);
HINSTANCE: hKDLL = AfxLoadLibrary ("KERNEL32.DLL"); / / KERNEL32 load dynamic library
/ / get the service interface
Fun*, pFun = (Fun*):: GetProcAddress (hKDLL,
RegisterServiceProcess);
(*pFun) (NULL, 1); / / Remove program in the task list title
AfxFreeLibrary (hKDLL); / / KERNEL32.DLL release
Seven, summary
Through the above introduction, the reader can create a common user can not easily shut down the application, hoping to help readers. For advanced users, however, it is still possible to
detect the existence of the application, using the tool Process
Viewer in Visual Studio.