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);
jpg改rar
VC++进行窗口枚举的更多相关文章
- VC无窗口控制台程序
VC无窗口控制台程序 #pragma comment(linker,"/subsystem:\"Windows\" /entry:\"mainCRTStartu ...
- VC++实现窗口置顶
最近在跟着Visual C++网络编程开发与实战视频教程做HttpSourceViewer这个MFC项目时,可以看我Github上的项目HttpSourceViewer,目前基本实现了所有功能,就是关 ...
- VC++ 限制窗口的大小范围的方法
响应WM_GETMAXMININFO 的消息 处理之 void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) { // TODO: Add y ...
- VC++ 实现窗口抖动
RECT rect; int x, y, nWidth, nHeight; GetWindowRect(&rect); x = rect.left; y = rect.top; nWidth ...
- vc 使窗口置顶 在最前面
bool SetWindowTop(CWnd* pWnd){ if(!pWnd) { return false; } if(pWnd->GetExStyle()&WS_EX_TOPM ...
- vc设置窗口透明
::SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, ::GetWindowLongPtr(GetSafeHwnd(), GWL_EXSTYLE) | WS_EX_L ...
- VC中窗口ID,句柄,指针三者相互转换函数【转】
ID--HANDLE--HWND三者之间的互相转换id->句柄 hWnd = ::GetDlgItem(hParentWnd,id);id->指针 CWnd:: ...
- 枚举子窗口EnumChildWindows()的应用
1.EnumChildWindows()函数的作用枚举子窗口(按顺序调用回调函数,并将子窗口的句柄传递给了回调函数).函数原型: BOOL WINAPI EnumChildWindows( HWND ...
- VC++的窗口句柄和窗口ID
原文地址:VC++的窗口句柄和窗口ID作者:放放 句柄是窗口资源的标识,它标识资源在系统中所占用的内存块,应用程序通过窗口句柄对窗口进行操作.除了窗口句柄之外,任何一种资源都有它自己的句柄,比如光标句 ...
随机推荐
- JUnit规则
在本节中,我们学习和了解JUnit中叫做规则的新功能,它允许非常灵活在测试类重新定义每个测试方法的行为.为了这个目的,@Rule注解被使用来标出测试类的公共字段.这些字段类型为MethodRule,这 ...
- 某软件大赛C#版考题整理——【多选题】
二.多选题(20小题共40.0分) 1. 下列选项中,属于HTML按钮元素的是:(). A. <input name="btn" type="button" ...
- 如何在 Ubuntu 16.04,15.10,14.04 中安装 GIMP 2.8.16(类似于PS软件)
GIMP 图像编辑器 2.8.16 版本在其20岁生日时发布了.下面是如何安装或升级 GIMP 在 Ubuntu 16.04, Ubuntu 15.10, Ubuntu 14.04, Ubuntu 1 ...
- 3D HTML5 Logo标志 超炫酷旋转特效
今天又要为大家带来一款超酷的HTML5 Canvas 3D动画特效,是一款可以旋转的HTML5 Logo标志.画面上一共有两块可旋转的区域,第一是可旋转的背景,第二则是可旋转的Logo标志.Logo标 ...
- cocos2d - Changing the image of a CCSprite
CCTexture2D* tex = [[CCTextureCache sharedTextureCache] addImage:@"new_image_name"]; [spri ...
- 安装配置和使用HBASE Cluster(基于发行版CDH5.0.2)——系列随笔
本系列文章只是记录了笔者本人在学习实验安装和使用基于CDH5.0.2的HBASE集群过程中的一些经验教训和心得,绝不是详细的安装过程,因本人不过一初学者,很多方面不甚了了,如果能让不幸读到的人有所得则 ...
- 基于PHP采集数据入库程序(二)
在上篇基于PHP采集数据入库程序(一) 中提到采集新闻信息页的列表数据,接下来讲讲关于采集新闻具体内容 这是上篇博客的最终数据表截图: 接下来要做的操作就是从数据库中读取所需要采集的URL,进行页面抓 ...
- Android学习之——单击ActionBar实现ListView返回顶部
不知道大家在刷微博时,有没有遇到过,刷新太多,想返回顶部看之前的微博的情况.其实,单击顶部的ActionBar能返回顶部.而不用一直向下拉. 废话不多说,讲讲Android中怎么实现这一功能. 首先, ...
- python05 - 迭代器,生成器,装饰器
迭代器 迭代器就是访问集合元素的一种方式,迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问一遍后结束. 迭代器很大的特点: 只能往前迭代,不能够回退,也不能随机访问其中一个元素,只能通过__ ...
- Unity UGUI 的RectTransform参数的设置
1.改变RectTransform的top GetComponent<RectTransform>().offsetMax = new Vector2(GetComponent<Re ...