This article describes an unlisted Win32 API function: Gettaskmanwindow, which uses it to manipulate windows ' taskbar. This function returns the window handle that owns the taskbar button. In Microsoft's MSDN documentation, the taskbar is described in the following way: "... The Windows interface contains a special Application desktop toolbar called the taskbar. The taskbar can be used to switch between different windows that are open, and to start a new application .... The taskbar contains start menus, taskbar buttons, shortcut menus, and status displays ... ". Unfortunately, there is no function to access the taskbar in the formal question of the Win32 API. Therefore we must use the Win32 API function that is not exposed.
Here is the prototype of Gettaskmanwindow:
typedef HWND (WINAPI *procgettaskmanwnd) (void); Procgettaskmanwnd gettaskmanwindow;void Main (int argc, char* argv[]) { if (argc<2) { printf ("usage:/n/ Ngetaskmanwnd.exe s| h/n "); return; } Hmodule HUser32 = GetModuleHandle ("user32"); if (!huser32) { return; } Gettaskmanwindow = (Procgettaskmanwnd) GetProcAddress (HUser32, "Gettaskmanwindow"); if (! Gettaskmanwindow) { return; } HWND hwnd = Gettaskmanwindow (); if (!hwnd) { return; } if (*argv[1]== ' h ' | | *argv[1]== ' h ') { ShowWindow (GetParent (hWnd), sw_hide); } else { ShowWindow (GetParent (hWnd), sw_show);} }
Method 2:
HWND
GetDesktopWindow(
VOID
);
BOOL
EnumChildWindows(
HWND
hWndParent,
WNDENUMPROC lpEnumFunc,
LPARAM
lParam
);
int
GetClassName(
HWND
hWnd,
LPTSTR
lpClassName,
int
nMaxCount
);
1) Get the desktop window
2) Traverse the child window of the desktop
3) The task bar is judged by the class name Shell_traywnd
4) then traverse the taskbar's sub-window to find the window you want
#include <windows.h> #include <stdio.h> BOOL CALLBACK Enumtaskbarwnds (HWND hwnd, LPARAM LPARAM) { char sz CLASS[256]; if (! GetWindow (hwnd, Gw_owner) && iswindowvisible (HWND)//filter out the window that is not displayed on the taskbar { getclassname (hwnd, Szclass, 25 6); if (strcmp (Szclass, "Shell_traywnd")! = 0//filter out taskbar itself && strcmp (szclass, "ProgMan")! = 0)//filter out desktop {
//This is the window you want. Char sztitle[256]; GetWindowText (hwnd, SzTitle, n); printf ("%s | %s\n ", SzTitle, Szclass); } End If }//end if return TRUE;} int main () { EnumWindows (enumtaskbarwnds, NULL); return 0;}
Method 3:
HWND G_hwndshell_traywnd = 0; BOOL CALLBACK EnumChildProc1 (HWND hwnd, LPARAM LPARAM) { TCHAR sztext[33] = {0}; if (0 = = GetClassName (hWnd, Sztext, +)) return TRUE; if (lstrcmp (Sztext, _t ("Shell_traywnd")) = = 0) { g_hwndshell_traywnd = hWnd; return FALSE; } return TRUE;} BOOL CALLBACK ENUMCHILDPROC2 (HWND hwnd, LPARAM LPARAM) { TCHAR sztext[33] = {0}; GetWindowText (HWnd, Sztext, +); MessageBox (NULL, Sztext, _t ("Caption"), MB_OK); return TRUE;} VOID Test () { enumchildwindows (:: GetDesktopWindow (), enumchildproc1,0);//Enum Desktop ' s child windows if (g _hwndshell_traywnd) enumchildwindows (G_hwndshell_traywnd, EnumChildProc2, 0);//Enum Tray ' s child windows}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
VC gets the handle of the taskbar window