Qt引用windows下的api函数findWindow出现的问题

houqijian956677281 2016-01-12 12:55:41
gameh=::FindWindow(L"",L"琪宝宝");
if(gameh == NULL)
{
qDebug() << "success";
}else
{
qDebug() << "fail";
}

得到HWND一直是NULL,这是为什么?
...全文
1588 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
sdghchj 2016-10-14
  • 打赏
  • 举报
回复
窗口标题改用英文试试。 或许QT用的UTF8,VC用的是GB
dustpg 2016-10-14
  • 打赏
  • 举报
回复
两个个参数是in_opt, 也就是说, 第一个参数要null才行
xqhrs232 2016-10-13
  • 打赏
  • 举报
回复
Qt引用windows下的api函数findWindow出现的问题???还可以这样玩?
houqijian956677281 2016-01-12
  • 打赏
  • 举报
回复
关键是它得到的结果老是NULL,如何才能不是NULL?
paschen 2016-01-12
  • 打赏
  • 举报
回复
if(gameh == NULL) 表示的是失败 else里表示的才是成功
zhouxiaofeng1021 2016-01-12
  • 打赏
  • 举报
回复
The FindWindow function retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. This function does not perform a case-sensitive search. To search child windows, beginning with a specified child window, use the FindWindowEx function. Syntax HWND FindWindow( LPCTSTR lpClassName, LPCTSTR lpWindowName ); Parameters lpClassName [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 in the low-order word of lpClassName; the high-order word must be zero. If lpClassName points to 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. If lpClassName is NULL, it finds any window whose title matches the lpWindowName parameter. lpWindowName [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 name and window name. If the function fails, the return value is NULL. To get extended error information, call GetLastError. Remarks If the lpWindowName parameter is not NULL, FindWindow calls the GetWindowText function to retrieve the window name for comparison. For a description of a potential problem that can arise, see the Remarks for GetWindowText. To check if the Microsoft IntelliType version 1.x software is running, call FindWindow as follows: FindWindow("MSITPro::EventQueue",NULL); To check if the IntelliType version 2.0 software is running, call FindWindow as follows: FindWindow("Type32_Main_Window", NULL); If the IntelliType software is running, it sends WM_APPCOMMAND messages to the application. Otherwise the application must install a hook to receive WM_APPCOMMAND messages. Microsoft Windows 95 or later: FindWindowW 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 World Wide Web link. Example For an example, see Retrieving the Number of Mouse Wheel Scroll Lines. Function Information Minimum DLL Version user32.dll Header Declared in Winuser.h, include Windows.h Import library User32.lib Minimum operating systems Windows 95, Windows NT 3.1 Unicode Implemented as ANSI and Unicode versions. See Also Windows Overview, EnumWindows, FindWindowEx, GetClassName, GetWindowText, RegisterClass, RegisterClassEx
赵4老师 2016-01-12
  • 打赏
  • 举报
回复
//先使用Spy++获取窗口"琪宝宝"对应的窗口类名,替换下面代码中的(窗口类名)
::FindWindowW(L"(窗口类名)",L"琪宝宝");
houqijian956677281 2016-01-12
  • 打赏
  • 举报
回复
spy++显示就是这个 我复制上去的 就是不行,是不是Qt Creator的编码问题呀?
paschen 2016-01-12
  • 打赏
  • 举报
回复
引用 2 楼 houqijian956677281 的回复:
关键是它得到的结果老是NULL,如何才能不是NULL?
可能窗口名输错了,用spy++获得后把窗口名完整复制过来
paschen 2016-01-12
  • 打赏
  • 举报
回复
另外可以调用GetLastError 检查失败原因 https://msdn.microsoft.com/en-us/library/ms633499%28VS.85%29.aspx

24,855

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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