我的代码如下:
LPDWORD yb_handle = NULL;
HWND w_handle = (HWND)FindWindow(NULL,"YB_OnlineClient");
if(w_handle != NULL){
MessageBox("成功找到窗口");
GetWindowThreadProcessId(window_handle,yb_handle);
if(yb_handle != NULL)
MessageBox("成功得到创建的进程");
}
第一个MessageBox可以弹出来,第二个就不能,为什么呢?调用GetLastError()返回的是1400,也就是"无效的窗口句柄",
FindWindow的返回值:
Return Values
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. 我的代码:
if(w_handle != NULL)
MessageBox("成功找到窗口");
说明FindWindow没问题啊,并且在这个地方调用GetLastError()返回是0啊,没问题啊.是不是跟FindWindow中的LPCTSTR lpClassName这个参数有关系啊?这个参数如何获取啊?
If lpClassName is NULL, it finds any window whose title matches the lpWindowName parameter.
帮忙看看,多谢.
LPDWORD yb_handle = NULL;
HWND w_handle = (HWND)FindWindow(NULL,"YB_OnlineClient");
if(w_handle != NULL){
MessageBox("成功找到窗口");
GetWindowThreadProcessId(window_handle,yb_handle);
if(yb_handle != NULL)
MessageBox("成功得到创建的进程");
}
第一个MessageBox可以弹出来,第二个就不能,为什么呢?调用GetLastError()返回的是1400,也就是"无效的窗口句柄",
FindWindow的返回值:
Return Values
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. 我的代码:
if(w_handle != NULL)
MessageBox("成功找到窗口");
说明FindWindow没问题啊,并且在这个地方调用GetLastError()返回是0啊,没问题啊.是不是跟FindWindow中的LPCTSTR lpClassName这个参数有关系啊?这个参数如何获取啊?
If lpClassName is NULL, it finds any window whose title matches the lpWindowName parameter.
帮忙看看,多谢.
DWORD processID;HWND hWnd = (HWND)FindWindow(NULL,"YB_OnlineClient");
if(hWnd != NULL){
MessageBox("成功找到窗口");
DWORD threadID = GetWindowThreadProcessId(hWnd,&processID);
if(threadID != NULL){
MessageBox("成功得到创建的进程");
}
}
=====================================================================
这个是写错了,按照gomoku 的代码也是不行,第2个MessageBox也是弹不出来,为什么呢?
if(hwnd != NULL)
{
DWORD dwThreadId = 0;
GetWindowThreadProcessId(hwnd, &dwThreadId);
if(dwThreadId != 0)
{
::MessageBox(NULL, L"HELLO", L"HELLO", MB_OK);
}
}