Reputation: 11
I am trying to get Window text of the other MFC application in the loop (I am getting a handle of that other process using ProcessId). But, sometimes I am getting it blank. When I do some activity on that other MFC application I sometimes get the Window text and sometimes it's gone. I tried with GetLastError but it returns 0 when it is GetWindowText return blank. So is there any way I can find out what can be a possible mistake in my application or that other MFC application?
Example code :
HWND hWnd = GetProcessHWND(<processid>); //This is function created to get
hWnd using process id
if (hWnd)
{
CWnd *pWnd = CWnd::FromHandle(hWnd);
while (pWnd->GetParent())
{
pWnd = pWnd->GetParent();
}
TCHAR chTitle[MAX_PATH];
pWnd->GetWindowText(chTitle, MAX_PATH);
}
Upvotes: 0
Views: 778
Reputation: 1483
Does your program run with normal user privileges or with full admin rights? If you cannot get the window text from programs running with full admin rights it might be due to the fact that Microsoft has introduced the "User Interface Privilege Isolation (UIPI) message filter" with Windows Vista: By default, a process cannot send a window message to another process with a higher integrity level.
If this is the case and you have the source code of the programs that do not give valid results you can use the API ChangeWindowMessageFilterEx (Windows 7 / Server 2008 R2 and up) to allow selected or ChangeWindowMessageFilter (Windows Vista / Server 2008) to allow all messages from a non privileged program to reach a process that runs with higher privileges.
Upvotes: 1