关于FindWindow查找窗口的问题

shjqk 2007-04-16 05:34:29
我使用SPY++查找到一个应用程序的类名,和标题一起可以找到该窗口
HWND hMainWindow;
hMainWindow = ::FindWindow( "ARE9D707-5162-4C96-A2B0-3DA65AGER30D","TEST");
//找到后,我想找窗口弹出的一个登陆框,发现如果只通过标题"LOGIN"可以找到
但是如果通过类名+标题就找不到了,不知道为什么
HWND hLoginWindow;
hLoginWindow = ::FindWindow( NULL,"Login" );//可以找到
hLoginWindow = ::FindWindow( "#32770(Dialog)","Login" ); //找不到
这个类名是通过SPY++复制的,应该不会有什么问题吧
如果光通过Login窗口我担心有其他同名窗口
请问这是什么原因?我该如何找到这个子窗口.
...全文
722 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
WingForce 2007-04-17
  • 打赏
  • 举报
回复
那就用FindWindowEx

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.
Return Value

If the function succeeds, the return value is a handle to the window that has the specified class and window names.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.




Remarks

If the lpszWindow parameter is not NULL, FindWindowEx calls the GetWindowText function to retrieve the window name for comparison. For a description of a potential problem that can arise, see the Remarks section of GetWindowText.

An application can call this function in the following way.

FindWindowEx( NULL, NULL, MAKEINTATOM(0x8000), NULL );
0x8000 is the atom for a menu class. When an application calls this function, the function checks whether a context menu is being displayed that the application created.

Windows 95 or later: FindWindowExW is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

shjqk 2007-04-17
  • 打赏
  • 举报
回复
谢谢!
那如果其他的对话框窗口如果是Login的标题,我该怎么判断呢?
能不能判断它是不是hMainWindow的子窗口
或者只查找hMainWindow下的标题为Login的窗口
WingForce 2007-04-16
  • 打赏
  • 举报
回复
The following table describes the system classes that are available only for use by the system. They are listed here for completeness sake.

Class Description
ComboLBox The class for the list box contained in a combo box.
DDEMLEvent Windows NT/Windows 2000/Windows XP: The class for Dynamic Data Exchange Management Library (DDEML) events.
Message Windows 2000/Windows XP: The class for a message-only window.
#32768 The class for a menu.
#32769 The class for the desktop window.
#32770 The class for a dialog box.
#32771 The class for the task switch window.
#32772 Windows NT/Windows 2000/Windows XP: The class for icon titles.
WingForce 2007-04-16
  • 打赏
  • 举报
回复
hLoginWindow = ::FindWindow( "#32770","Login" ); //找不到

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧