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. Active window holding problem

Active window holding problem

Scheduled Pinned Locked Moved C / C++ / MFC
help
5 Posts 3 Posters 0 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.
  • J Offline
    J Offline
    john5632
    wrote on last edited by
    #1

    Hi I wrote the code for minimising the application that are active while I launch my application. But one error is coming "cannot convert from 'HWND' to 'CWnd *'" CString szTitle; CWnd *pTopWnd; UINT cmd=GW_HWNDFIRST; while (pTopWnd=GetWindow(NULL,cmd)) { pTopWnd->GetWindowText(szTitle); if(szTitle.Find("MyApp.EXE")>=0) pTopWnd->ShowWindow(SW_HIDE); cmd=GW_HWNDNEXT; } Plz tell the solution

    S 1 Reply Last reply
    0
    • J john5632

      Hi I wrote the code for minimising the application that are active while I launch my application. But one error is coming "cannot convert from 'HWND' to 'CWnd *'" CString szTitle; CWnd *pTopWnd; UINT cmd=GW_HWNDFIRST; while (pTopWnd=GetWindow(NULL,cmd)) { pTopWnd->GetWindowText(szTitle); if(szTitle.Find("MyApp.EXE")>=0) pTopWnd->ShowWindow(SW_HIDE); cmd=GW_HWNDNEXT; } Plz tell the solution

      S Offline
      S Offline
      sw thi
      wrote on last edited by
      #2

      Your GetWindow() is returning an HWND and you are trying to assign that directly to a CWnd*. Do the following instead: HWND hWnd = GetWindow(NULL,cmd); CWnd *pTopWnd = CWnd::FromHandle(hWnd);

      "What's on your mind, if you will allow the overstatement?"

      J 1 Reply Last reply
      0
      • S sw thi

        Your GetWindow() is returning an HWND and you are trying to assign that directly to a CWnd*. Do the following instead: HWND hWnd = GetWindow(NULL,cmd); CWnd *pTopWnd = CWnd::FromHandle(hWnd);

        "What's on your mind, if you will allow the overstatement?"

        J Offline
        J Offline
        john5632
        wrote on last edited by
        #3

        I modified the code as : CString szTitle; HWND hWnd = GetWindow(NULL,GW_HWNDFIRST); CWnd *pTopWnd = CWnd::FromHandle(hWnd); while (pTopWnd!=NULL) { pTopWnd->GetWindowText(szTitle); if(szTitle.Find(_T("MyApp.EXE"))>=0) pTopWnd->ShowWindow(SW_HIDE); hWnd = GetWindow(NULL,GW_HWNDNEXT); pTopWnd = CWnd::FromHandle(hWnd); } But pTopWnd is coming NULL.Why?

        S D 2 Replies Last reply
        0
        • J john5632

          I modified the code as : CString szTitle; HWND hWnd = GetWindow(NULL,GW_HWNDFIRST); CWnd *pTopWnd = CWnd::FromHandle(hWnd); while (pTopWnd!=NULL) { pTopWnd->GetWindowText(szTitle); if(szTitle.Find(_T("MyApp.EXE"))>=0) pTopWnd->ShowWindow(SW_HIDE); hWnd = GetWindow(NULL,GW_HWNDNEXT); pTopWnd = CWnd::FromHandle(hWnd); } But pTopWnd is coming NULL.Why?

          S Offline
          S Offline
          sw thi
          wrote on last edited by
          #4

          You are passing NULL as the first parameter to GetWindow, you have to provide a valid window handle to GetWindow then only it gets the next window or any window thats related to the window that you provide. Use GetForegroundWindow function to get the handle to the current active window, then you can use GetWindow to get the next windows. Remember you always have to pass a valid HWND to GetWindow.

          "What's on your mind, if you will allow the overstatement?"

          1 Reply Last reply
          0
          • J john5632

            I modified the code as : CString szTitle; HWND hWnd = GetWindow(NULL,GW_HWNDFIRST); CWnd *pTopWnd = CWnd::FromHandle(hWnd); while (pTopWnd!=NULL) { pTopWnd->GetWindowText(szTitle); if(szTitle.Find(_T("MyApp.EXE"))>=0) pTopWnd->ShowWindow(SW_HIDE); hWnd = GetWindow(NULL,GW_HWNDNEXT); pTopWnd = CWnd::FromHandle(hWnd); } But pTopWnd is coming NULL.Why?

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            pther wrote:

            But pTopWnd is coming NULL.Why?

            Did you bother to check the return value of GetWindow(), or are you assuming it succeeded and calling FromHandle() anyway?


            "A good athlete is the result of a good and worthy opponent." - David Crow

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            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