Function function: This function gets a handle of a window that matches the window name and the window name matches a given string. This function looks for the sub-window, starting from the next sub-window behind a given sub-window. Not case sensitive when looking up. Function prototype: HWnd FindWindowEx (HWND HWndParent, HWND HWNDMAFTER, LPCTSTR LPSZCLASS, LPCTSTSTSTSZWINDOW); parameter; hWndParent: To find the parent window handle of the child window. If hwnjparent is NULL, the function is used as the parent window at the desktop window, and looks for all sub-windows of the desktop window. Windows NT5.0 and later: If hwndparent is hwnd_message, the function only looks for all message windows. HWNDCHILDAFTER: Sub window handle. Find starting from the next sub-window in the z-order. The sub-window must be a direct sub-window of the HWndParert window instead of the post-generation window. If hwndchildafter is NULL, look up starting from the first sub-window from HWNDPART. If hwndparent and hwndchildafter are simultaneously NULL, the function looks for all top-level windows and message windows. LPSZCLASS: Points to a null end string specified by the class name, or a pointer to a member identifying a class string. If this parameter is a member, it must be a global member generated by the THEGLOBAIADDATOM function before. The member is 16 bits and must be 16 bits of LPClassName, and the high position must be 0. LPSZWindow: Points an empty end string specified by the window name (window title). If this parameter is null, all windows are all matched. Return Value: If the function is successful, the return value is a window handle with the specified class name and window name. If the function fails, the return value is NULL. To get more error messages, call the getLastError function. Quick check NT: 4.0 to the above version; Windows: 95 or more version; Windows CE: does not support; header file: winuser.h; library file: user32. LIB; Unicode: Different from both Windows NT to Unicode and ANSI versions.
Example 1.
Unit Unitwinexe;
Interface
Uses Windows, Messages, Dialogs;
ImplementationVar fHWND, ChWND: THANDLE; CMDLINE: STRING; Begin Cmdline: = 'C: / Program Files / Huawei-3COM / H3C 802.1X Client / Dot1xClient.exe'; Winexec (Pchar (cmdline), SW_HIDE);
fHWnd: = FindWindow ('# 32770', nil); // Find to the window # 32770, '# 32770' It is found in SPY .
If FHWND> 0 THEN ChWND: = FindWindowEx (fHWND, 0, NIL, 'connection'); // Find # 32770 Sub-window 'connection' if chwnd> 0 Then PostMessage (ChWnd, WM_KeyDown, vk_return, 0); / / Press the Enter key End; End.
Example 2. Comprehensive Control Windows Task Bar
analysis:
From the system functional point of view, the entire taskbar includes several different sub-areas, from left to right: Start button, Application Switch Bar, taskbar notification area (Notification Area), and taskbar clock . Similarly to other Windows applications, the taskbar program (Systray.exe) consists of several different forms, these forms have respective window class names, display mode, and other information. Therefore, as long as you get the relevant window information, you can fully control different areas of the Windows task bar. The window information of the taskbar form is: (I use SPY .) 1 The window class name of the taskbar is: shelltrayWnd. The window class name of the Start button is: Button. 3 The window class name of the application switching area is: RebarWindow32. 4 The window class name of the taskbar notification area is: TRAYNOTIFYWND. The window class name of the 5 taskbar clock is: TRAYCLOCKWCLASS. (2) Call the FindWindow function to get the window handle of the taskbar. (3) Call the FindWindowEx function to get the window handle of each sub-area of the taskbar. (4) According to the window handle, call the showWindow function to control the local area to display or hide (show / hide); call the EnableWindow function control taskbar valid or invalid (Enabled / Disabled).
code show as below:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class (TForm) CheckBox1: TCheckBox; procedure FormClose (Sender: TObject; var Action: TCloseAction); private {Private declarations} Wnd: array [0..4] of THandle; procedure GetHandles; procedure EnableOrDisable (Sender: TOBject); procedure HideOrShow (Sender: TObject); public {public declarations} end; var Form1: TForm1; implementation {$ R * .dfm} {tform1} procedure tform1.enableORDISABLE (Sender: Tobject); begin getHandles; if tcheckbox (sender) .Checked the case tcheckbox (sender) .tag of 0: enableWindow (WND [0], FALSE); 1 : EnableWindow (WND [1], FALSE); 2: EnableWindow (WND [2], FALSE); 3: EnableWindow (WND [3], FALSE); 4: EnableWindow (WND [4], FALSE); Else Case Tcheckbox (sender) .tag of 0: EnableWindow (WND [0], TRUE); 1: EnableWindow; 2: EnableWindow (WND [2], True); 3: EnableWindow (WND [3], TRUE); 4: EnableWindow (WND [4], TRUE); End; procedure tform1.gethandles; begin // gets the TRAY BAR window handle; WND [0]: = FindWindow ('shelltrayWnd', nil); // get the window handle of the start button; in WND [1]: = FINDWINDOW ('ShelltrayWnd', NIL); WND [1]: = FindWindowEx (WND [1], HWND (0), 'Button', NIL); // Get window handle of the application switching area; in WND [2]: = FindWindow ('shelltrayWnd', NIL); WND [2]: = FindWindowEx (WND [2], hwnd (0), 'rebarwindow32', nil); // Get window handle of the taskbar notification area; in WND [3 ]: = FindWindow ('ShelltrayWnd', NIL); WND [3]: = FindWindowEx (WND [3], HWnd (0), '