Cannot enumerate with EnumWindows
-
Hi, After starting some certain applications with ShellExecuteEx() function and getting their process handles in return, on some other event I want to get the CWnd handle to those windows and bring them to the front and resize, for which I use SetWindowPos. How I try to get the mentioned CWnd handle: - After starting the application, I get the process ID with
OpenedThreadPID = GetProcessId(ProcessHandle);
- Then I call EnumWindows function - and then in the callback function I check the called window's process ID withGetWindowThreadProcessId(pWnd->m_hWnd,&FoundThreadPID); if(FoundThreadPID == OpenedThreadPID) SearchedCwnd = pWnd;
- Then I useSetWindowPos(&SearchedCwnd->wndTopMost,StartX,StartY,Width,Height, SWP_NOREPOSITION|SWP_NOSENDCHANGING|SWP_NOZORDER|SWP_SHOWWINDOW );
The callback function is not called. What am I doing wrong? BTW, can I also reach the windows minimized to tray? Any help appreciated. Thanks in advance Caykahve -
Hi, After starting some certain applications with ShellExecuteEx() function and getting their process handles in return, on some other event I want to get the CWnd handle to those windows and bring them to the front and resize, for which I use SetWindowPos. How I try to get the mentioned CWnd handle: - After starting the application, I get the process ID with
OpenedThreadPID = GetProcessId(ProcessHandle);
- Then I call EnumWindows function - and then in the callback function I check the called window's process ID withGetWindowThreadProcessId(pWnd->m_hWnd,&FoundThreadPID); if(FoundThreadPID == OpenedThreadPID) SearchedCwnd = pWnd;
- Then I useSetWindowPos(&SearchedCwnd->wndTopMost,StartX,StartY,Width,Height, SWP_NOREPOSITION|SWP_NOSENDCHANGING|SWP_NOZORDER|SWP_SHOWWINDOW );
The callback function is not called. What am I doing wrong? BTW, can I also reach the windows minimized to tray? Any help appreciated. Thanks in advance CaykahveEnumWindows returns the raw HWND of the windows, not the CWnd of the windows. You should try to use raw Win32 API calls from within the EnumWindows callback instead of the MFC CWnd classes or CWnd pointers to windows. Then it will work fine.
-
EnumWindows returns the raw HWND of the windows, not the CWnd of the windows. You should try to use raw Win32 API calls from within the EnumWindows callback instead of the MFC CWnd classes or CWnd pointers to windows. Then it will work fine.
Actually I do it as told in Joseph Newcomer's article (http://www.codeproject.com/cpp/callbacks.asp?msg=27622) And the CWnd is retrieved by CWnd::FromHandle(). Why is that a problem?
-
Actually I do it as told in Joseph Newcomer's article (http://www.codeproject.com/cpp/callbacks.asp?msg=27622) And the CWnd is retrieved by CWnd::FromHandle(). Why is that a problem?
Not necessarily a problem, it could use up memory a lot depending upon what you do in the enumeration, since each CWnd created this way is a temporary added to a map. I just try to avoid doing anything MFC related in a callback like that. I am not sure what Joseph did. Threre might be a separate problem in your code. BTW: I tried to e-mail you a sample, but your GMail address might be bad.