如何获取别的进程窗口弹出的系统对话框的句柄
根据两种方法,标题和类名,找出来的句柄都是0
classhwndFather 是父窗口句柄。通过spy_++获得。
用什么正确方法可以获取?
strcpy(szTitleFind,"导出对话框");
classhwndMsgbox= FindTitleWnd(classhwndFather, szTitleFind);
printf("classhwndMsgbox:%d\r\n", classhwndMsgbox);
//类名:#32770 (Dialog)
classhwndMsgbox=FindWithClassName(classhwndFather,"#32770");
printf("classhwndMsgbox:%d\r\n", classhwndMsgbox);
HWND FindTitleWnd(HWND ParentWnd,char szTitleFind[512])
{
HWND hChild = ::GetWindow(ParentWnd, GW_CHILD);
for(; hChild!=NULL ; hChild=::GetWindow(hChild,GW_HWNDNEXT))
{
//判断是否为需要的控件
//if ( GetDlgCtrlID(hChild) == ControlID )
char szTitle[512];
GetWindowText(hChild, szTitle, 512);
if (strcmp(szTitleFind,szTitle)==0)
return hChild;
HWND FindWnd=FindTitleWnd(hChild,szTitleFind);
if (FindWnd)
return FindWnd;
}
return NULL;
}
HWND FindWithClassName(HWND ParentWnd,const TCHAR* FindClassName)
{
HWND hChild = ::GetWindow(ParentWnd, GW_CHILD);
TCHAR ClassName[100];
for(; hChild!=NULL ; hChild=::GetWindow(hChild,GW_HWNDNEXT))
{
::GetClassName(hChild,ClassName,sizeof(ClassName)/sizeof(TCHAR));
if (_tcscmp(ClassName,FindClassName)==0)
return hChild;
HWND FindWnd=FindWithClassName(hChild,FindClassName);
if (FindWnd)
return FindWnd;
}
return NULL;
}





classhwndFather 是父窗口句柄。通过spy_++获得。
用什么正确方法可以获取?
strcpy(szTitleFind,"导出对话框");
classhwndMsgbox= FindTitleWnd(classhwndFather, szTitleFind);
printf("classhwndMsgbox:%d\r\n", classhwndMsgbox);
//类名:#32770 (Dialog)
classhwndMsgbox=FindWithClassName(classhwndFather,"#32770");
printf("classhwndMsgbox:%d\r\n", classhwndMsgbox);
HWND FindTitleWnd(HWND ParentWnd,char szTitleFind[512])
{
HWND hChild = ::GetWindow(ParentWnd, GW_CHILD);
for(; hChild!=NULL ; hChild=::GetWindow(hChild,GW_HWNDNEXT))
{
//判断是否为需要的控件
//if ( GetDlgCtrlID(hChild) == ControlID )
char szTitle[512];
GetWindowText(hChild, szTitle, 512);
if (strcmp(szTitleFind,szTitle)==0)
return hChild;
HWND FindWnd=FindTitleWnd(hChild,szTitleFind);
if (FindWnd)
return FindWnd;
}
return NULL;
}
HWND FindWithClassName(HWND ParentWnd,const TCHAR* FindClassName)
{
HWND hChild = ::GetWindow(ParentWnd, GW_CHILD);
TCHAR ClassName[100];
for(; hChild!=NULL ; hChild=::GetWindow(hChild,GW_HWNDNEXT))
{
::GetClassName(hChild,ClassName,sizeof(ClassName)/sizeof(TCHAR));
if (_tcscmp(ClassName,FindClassName)==0)
return hChild;
HWND FindWnd=FindWithClassName(hChild,FindClassName);
if (FindWnd)
return FindWnd;
}
return NULL;
}





...全文
相关推荐
C#通过进程名获取窗口句柄
C#通过进程名获取窗口句柄,也可以获取当前窗口句柄。本人在c#2013测试通过。
利用Spy++和编程语言获取窗口句柄的技巧与实践
窗口句柄,或称为句柄(Handle),是Windows操作系统中用于标识资源(如窗口、图标、文件等)的唯一标识符。理解句柄的概念对于进行Windows编程至关重要,因为几乎所有的Windows API函数都需要使用句柄来指定操作的目标资源。启动Spy++后,你会看到一个界面,它包含几个主要部分:窗口工具:位于界面顶部,是Spy++的主要功能区域。这里包含用于浏览和搜索应用程序窗口和控件的工具。进程列表:显示所有当前运行的进程,用户可以选择一个进程以查看该进程下的所有窗口。
Windows窗口句柄遍历与条件筛选实战详解
尽管名为“顶层”,但这些窗口并非按深度排序,而是按照Z-order的顺序被枚举——即从最顶层(最前)到底层(桌面背后)依次访问。Z-order 是Windows管理窗口堆叠关系的核心机制,决定了哪个窗口接收输入、哪个被遮挡。可以通过函数链式访问来手动遍历Z-order:// 获取最顶层窗口// 处理窗口...// 下一个Z-order层级的窗口这与的顺序一致吗?答案是:不一定完全相同。特性起始点最顶层窗口最顶层窗口遍历方向。
通过进程id获取主窗口句柄及主窗口标题
通过进程id获取到所在进程的主窗口的句柄,及通过该主窗口句柄获取当前主窗口的标题,进程名;这是一个demo例程,仅供参考
VC由进程ID获取窗口句柄
VC由进程ID获取窗口句柄VC由进程ID获取窗口句柄


