拿到某个进程内的窗口名称,两个方法不一样GetWindowText SendMessage,该如何处理
拿到某个进程内的窗口名称,两个方法不一样GetWindowText SendMessage
------解决方案--------------------
MSDN上说的很清楚
If the target window is owned by the current process, GetWindowText causes a WM_GETTEXT message to be sent to the specified window or control. If the target window is owned by another process and has a caption, GetWindowText retrieves the window caption text. If the window does not have a caption, the return value is a null string. This behavior is by design. It allows applications to call GetWindowText without becoming unresponsive if the process that owns the target window is not responding. However, if the target window is not responding and it belongs to the calling application, GetWindowText will cause the calling application to become unresponsive.
To retrieve the text of a control in another process, send a WM_GETTEXT message directly instead of calling GetWindowText.
- C/C++ code
TCHAR buf[WINDOW_TEXT_LENGTH]; SendMessage(hWnd, WM_GETTEXT, WINDOW_TEXT_LENGTH, (LPARAM)buf); wprintf(L"%s/n", buf); TRACE("控件子窗口名字!--");OutputDebugString(buf);TRACE("\r\n"); CString strtemp=_T(""); CWnd* p = CWnd::FromHandle(hWnd); p->GetWindowText(strtemp); TRACE("窗口名字!--");OutputDebugString(strtemp);TRACE("\r\n");
------解决方案--------------------
MSDN上说的很清楚
If the target window is owned by the current process, GetWindowText causes a WM_GETTEXT message to be sent to the specified window or control. If the target window is owned by another process and has a caption, GetWindowText retrieves the window caption text. If the window does not have a caption, the return value is a null string. This behavior is by design. It allows applications to call GetWindowText without becoming unresponsive if the process that owns the target window is not responding. However, if the target window is not responding and it belongs to the calling application, GetWindowText will cause the calling application to become unresponsive.
To retrieve the text of a control in another process, send a WM_GETTEXT message directly instead of calling GetWindowText.