Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Cannot enumerate with EnumWindows

Cannot enumerate with EnumWindows

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
4 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    caykahve
    wrote on last edited by
    #1

    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 with GetWindowThreadProcessId(pWnd->m_hWnd,&FoundThreadPID); if(FoundThreadPID == OpenedThreadPID) SearchedCwnd = pWnd; - Then I use SetWindowPos(&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

    B 1 Reply Last reply
    0
    • C 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 with GetWindowThreadProcessId(pWnd->m_hWnd,&FoundThreadPID); if(FoundThreadPID == OpenedThreadPID) SearchedCwnd = pWnd; - Then I use SetWindowPos(&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

      B Offline
      B Offline
      Blake Miller
      wrote on last edited by
      #2

      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.

      C 1 Reply Last reply
      0
      • B Blake Miller

        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.

        C Offline
        C Offline
        caykahve
        wrote on last edited by
        #3

        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?

        B 1 Reply Last reply
        0
        • C caykahve

          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?

          B Offline
          B Offline
          Blake Miller
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups