VC++進行視窗列舉
借鑑內容來自VC++驛站:VC驛站
①、使用 GetWindow 進行視窗列舉:
This function retrieves the handle to a window that has the specified relationship to the specified window.
HWND GetWindow(
HWND hWnd,
UINT uCmd
);
Parameters:
hWnd
[in] Handle to a window. The window handle retrieved is relative to this window, based on the value of the uCmd parameter.
uCmd
[in] Specifies the relationship between the specified window and the window whose handle is to be retrieved.
TCHAR titleText[MAX_PATH] = {0};
HWND nHwnd = ::GetWindow(::GetDesktopWindow(), GW_CHILD);
while(nHwnd != NULL) {
::GetWindowText(nHwnd, titleText, MAX_PATH);
if (_tcslen(titleText) > 0) MessageBox(titleText);
nHwnd = ::GetWindow(nHwnd, GW_HWNDNEXT);
}
②、使用 FindWindowEx 進行視窗列舉:
1)This function retrieves the handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows.
HWND FindWindow(
LPCTSTR lpClassName,
LPCTSTR lpWindowName
);
Parameters:
lpClassName
[in] Long pointer to a null-terminated string that specifies the class name or is an atom that identifies the class-name string. If this parameter is an atom, it must be a global atom created by a previous call to the GlobalAddAtom function. The atom, a 16-bit
value, must be placed in the low-order word of lpClassName; the high-order word must be zero.
lpWindowName
[in] Long pointer to a null-terminated string that specifies the window name (the window's title). If this parameter is NULL, all window names match.
2)The FindWindowEx function retrieves a handle to a window whose class name and window name match the specified strings. The function searches child windows, beginning with the one following the specified child window. This function does not perform a case-sensitive
search.
Syntax
HWND FindWindowEx( HWND hwndParent,
HWND hwndChildAfter,
LPCTSTR lpszClass,
LPCTSTR lpszWindow
);
Parameters:
hwndParent
[in] Handle to the parent window whose child windows are to be searched.
If hwndParent is NULL, the function uses the desktop window as the parent window. The function searches among windows that are child windows of the desktop.
Microsoft Windows 2000 and Windows XP: If hwndParent is HWND_MESSAGE, the function searches all message-only windows.
hwndChildAfter
[in] Handle to a child window. The search begins with the next child window in the Z order. The child window must be a direct child window of hwndParent, not just a descendant window.
If hwndChildAfter is NULL, the search begins with the first child window of hwndParent.
Note that if both hwndParent and hwndChildAfter are NULL, the function searches all top-level and message-only windows.
lpszClass
[in]
Pointer to a null-terminated string that specifies the class name or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be placed in the low-order word of lpszClass; the high-order word must be zero.
If lpszClass is a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, or any of the predefined control-class names, or it can be MAKEINTATOM(0x800). In this latter case, 0x8000 is the
atom for a menu class. For more information, see the Remarks section of this topic.
lpszWindow
[in] Pointer to a null-terminated string that specifies the window name (the window's title). If this parameter is NULL, all window names match.
TCHAR titleText[MAX_PATH] = {0};
HWND nHwnd = ::FindWindow(NULL, NULL);
while(nHwnd != NULL) {
::GetWindowText(nHwnd, titleText, MAX_PATH);
if (_tcslen(titleText) > 0) MessageBox(titleText);
nHwnd = ::FindWindowEx(0, nHwnd, NULL, NULL);
}
③、使用 EnumWindows 進行視窗列舉:
This function enumerates all top-level windows on the screen by passing the handle to each window, in turn, to an application-defined callback function. EnumWindows continues until the last top-level window is enumerated or the callback function returns FALSE.
BOOL EnumWindows(
WNDENUMPROC lpEnumFunc,
LPARAM lParam
);
Parameters:
lpEnumFunc
[in] Long pointer to an application-defined callback function. For more information, see EnumWindowsProc.
lParam
[in, out] Specifies an application-defined value to be passed to the callback function.
EnumWindows(EnumWindowsProc, NULL);
……
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
TCHAR titleText[MAX_PATH] = {0};
::GetWindowText(hwnd, titleText, MAX_PATH);
if (_tcslen(titleText) > 0) AfxMessageBox(titleText);
return TRUE;
}
④、使用 EnumChildWindows 進行子視窗的列舉:
EnumChildWindows 照比 EnumWindows 只是多了一個指定父視窗的視窗控制程式碼的引數.
The EnumChildWindows function enumerates the child windows that belong to the specified parent window by passing the handle to each child window, in turn, to an application-defined callback function. EnumChildWindows continues until the last child window is
enumerated or the callback function returns FALSE.
Syntax
BOOL EnumChildWindows( HWND hWndParent,
WNDENUMPROC lpEnumFunc,
LPARAM lParam
);
Parameters:
hWndParent
[in]
Handle to the parent window whose child windows are to be enumerated. If this parameter is NULL, this function is equivalent to EnumWindows.
Windows 95/98/Me: hWndParent cannot be NULL.
lpEnumFunc
[in] Pointer to an application-defined callback function. For more information, see EnumChildProc.
lParam
[in] Specifies an application-defined value to be passed to the callback function.
Return Value
⑤、使用 FindWindow 進行視窗的查詢:
HWND hCalc = ::FindWindow(_T("SciCalc"), _T("計算器"));
if (hCalc){
::SetWindowText(hCalc, _T("VC驛站 專用計算器!"));
}
⑥、使用 FindWindowEx 進行子視窗的查詢:
HWND hCalc = ::FindWindow(_T("SciCalc"), _T("計算器"));
if (hCalc){
::SetWindowText(hCalc, _T("VC驛站 專用計算器!"));
HWND hEdit = ::FindWindowEx(hCalc, NULL, _T("Edit"), NULL);
::SetWindowText(hEdit, _T("1234567890"));
//::SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)_T("1234567890"));
}
⑦、鑑於 FindWindowEx 找子控制元件的不確定性,
可以使用 GetDlgItem 來獲取對話方塊內部的子控制元件視窗控制程式碼:
HWND hEdit = ::GetDlgItem(hCalc, 0x193);
相關文章
- 使用微軟Detours庫進行模組列舉微軟
- 在C#中對列舉進行位運算--列舉組合C#
- 在 CTreeCtrl 中列舉系統中的所有視窗!(I) (轉)
- 在 CTreeCtrl 中列舉系統中的所有視窗!(II) (轉)
- 用VC++實現不規則視窗 (轉)C++
- 在不把視窗設定成當前視窗的條件下,對視窗進行操作。
- 使用Windows API進行GDI視窗繪圖WindowsAPI繪圖
- 工作列視窗以及其子視窗結構 (轉)
- 視窗最大值陣列陣列
- UIBarButtonSystemItem 列舉樣式檢視UIMIT
- vc++ 建立異性窗體(1)C++
- 第二課DOS命令列視窗命令列
- 應用例項:VC++實現廣告視窗自動關閉(轉)C++
- 如何凍結excel指定行和列 表格怎麼同時凍結行和列的視窗Excel
- win10如何取消工作列視窗_win10怎麼取消工作列預覽視窗Win10
- Java列舉類學習到進階Java
- Java 列舉、JPA 和 PostgreSQL 列舉JavaSQL
- [待]生成視窗最大值陣列陣列
- HDU 4937 Lucky Number(列舉進位制)
- 列舉和列舉的取值範圍
- 百錢買百雞(列舉思想編寫,並進行3次優化)優化
- 同一個語句在plsql的sql視窗可以執行命令視窗不能執行SQL
- WPF 透過 SetWindowDisplayAffinity 配置禁止對視窗進行截圖或錄屏
- Java列舉Java
- Swift,列舉Swift
- day99:MoFang:Flask-JSONRPC提供RPC介面&在APP進行視窗頁面操作(視窗-幀-幀組)FlaskJSONRPCAPP
- WPF視窗最大化(不覆蓋工作列)
- pb9 資料視窗的計算列
- JAVA 程式 在 cmd 視窗的執行Java
- C# 列舉與位列舉概述C#
- 列舉工具類
- TypeScript 列舉enumTypeScript
- Java 列舉(enum)Java
- Swift-列舉Swift
- 自定義列舉
- java列舉類Java
- TypeScript 列舉指南TypeScript
- Java列舉使用Java