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. How to get the MDI child window

How to get the MDI child window

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
8 Posts 2 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.
  • S Offline
    S Offline
    Sarvan AL
    wrote on last edited by
    #1

    Hi all, In my MDI application, I need to repaint a child window, which has title "Child Window 3", from the application class. How to use FindWindowEx function to get the window handle of the child window? Or is there an alternative? Kindly suggest me some ideas. Thanks in advance, Sarvan AL

    R 1 Reply Last reply
    0
    • S Sarvan AL

      Hi all, In my MDI application, I need to repaint a child window, which has title "Child Window 3", from the application class. How to use FindWindowEx function to get the window handle of the child window? Or is there an alternative? Kindly suggest me some ideas. Thanks in advance, Sarvan AL

      R Offline
      R Offline
      Russell
      wrote on last edited by
      #2

      What is the problem with FindWindowEx ? Elseway, could you create manually a simple loop to find the desired window in the windows list? Or UpdateAllView(NULL) probally cold be the more easy solution (but it takes some CPU time)!

      S 1 Reply Last reply
      0
      • R Russell

        What is the problem with FindWindowEx ? Elseway, could you create manually a simple loop to find the desired window in the windows list? Or UpdateAllView(NULL) probally cold be the more easy solution (but it takes some CPU time)!

        S Offline
        S Offline
        Sarvan AL
        wrote on last edited by
        #3

        Hi Russell, FindWindowEx always gives NULL. When I click on New, a new child window opens with titile "MyView1", "MyView2",... When I click this menu item, I want the child windows to be repainted one at a time. Pls have a look at the code:

        void CMainFrame::OnUpdateViews()
        {
        CString strTitle ;
        static int nChild = 1 ;

        strTitle.Format("MyView%d", nChild) ;
        
        HWND hWnd = ::FindWindowEx(
                            this->GetSafeHwnd(),
        		NULL, 
        		"CMyView", 
        		(LPSTR)(LPCTSTR) strTitle) ;
        
        if(::IsWindow(hWnd))
        	::SendMessage(hWnd, WM\_COMMAND, (WPARAM)WM\_USER, 0) ;
        

        // SendMessageToDescendants(WM_COMMAND, (WPARAM)WM_USER) ;

        nChild ++ ;
        

        }

        In my WM_USER handler, I simply call "Invalidate()". Instead of repainting all the children, I need to do it for a specific child window. Hope I have explained my problem clearly. Sarvan AL -- modified at 7:55 Tuesday 2nd May, 2006

        R 1 Reply Last reply
        0
        • S Sarvan AL

          Hi Russell, FindWindowEx always gives NULL. When I click on New, a new child window opens with titile "MyView1", "MyView2",... When I click this menu item, I want the child windows to be repainted one at a time. Pls have a look at the code:

          void CMainFrame::OnUpdateViews()
          {
          CString strTitle ;
          static int nChild = 1 ;

          strTitle.Format("MyView%d", nChild) ;
          
          HWND hWnd = ::FindWindowEx(
                              this->GetSafeHwnd(),
          		NULL, 
          		"CMyView", 
          		(LPSTR)(LPCTSTR) strTitle) ;
          
          if(::IsWindow(hWnd))
          	::SendMessage(hWnd, WM\_COMMAND, (WPARAM)WM\_USER, 0) ;
          

          // SendMessageToDescendants(WM_COMMAND, (WPARAM)WM_USER) ;

          nChild ++ ;
          

          }

          In my WM_USER handler, I simply call "Invalidate()". Instead of repainting all the children, I need to do it for a specific child window. Hope I have explained my problem clearly. Sarvan AL -- modified at 7:55 Tuesday 2nd May, 2006

          R Offline
          R Offline
          Russell
          wrote on last edited by
          #4

          Well, ...how to use this routine more times? the variable 'nChild' looks hard to be reset, or not? About your function: everything looks correct, but: The CView is child of a frame that is child of the MainFrame, I don't know if it is a problem for FindWindowEx. Are you sure that strTitle contains the right title? In debug mode you can check the RuntimeClass.

          S 1 Reply Last reply
          0
          • R Russell

            Well, ...how to use this routine more times? the variable 'nChild' looks hard to be reset, or not? About your function: everything looks correct, but: The CView is child of a frame that is child of the MainFrame, I don't know if it is a problem for FindWindowEx. Are you sure that strTitle contains the right title? In debug mode you can check the RuntimeClass.

            S Offline
            S Offline
            Sarvan AL
            wrote on last edited by
            #5

            Hi Russell, Pls forget abt 'nChild'. As you said, I tried this:

            HWND hWnd = ::FindWindowEx(MDIGetActive()->GetSafeHwnd(),
            				NULL, 
            				"CMyView", 
            				(LPSTR)(LPCTSTR) strTitle) ;
            

            But in vain. What else can solve this problem? Sarvan AL

            R 1 Reply Last reply
            0
            • S Sarvan AL

              Hi Russell, Pls forget abt 'nChild'. As you said, I tried this:

              HWND hWnd = ::FindWindowEx(MDIGetActive()->GetSafeHwnd(),
              				NULL, 
              				"CMyView", 
              				(LPSTR)(LPCTSTR) strTitle) ;
              

              But in vain. What else can solve this problem? Sarvan AL

              R Offline
              R Offline
              Russell
              wrote on last edited by
              #6

              I think that this must work: :-> POSITION ViewPos; CView* pView; CString string; ViewPos=pDoc->GetFirstViewPosition(); while(ViewPos){ pView=(CSWAView*) pDoc->GetNextView(ViewPos); pView->GetWindowText(string); if(string==strTitle){ ... } } In this way you could refresh more View (if exists) with the same name.

              S 1 Reply Last reply
              0
              • R Russell

                I think that this must work: :-> POSITION ViewPos; CView* pView; CString string; ViewPos=pDoc->GetFirstViewPosition(); while(ViewPos){ pView=(CSWAView*) pDoc->GetNextView(ViewPos); pView->GetWindowText(string); if(string==strTitle){ ... } } In this way you could refresh more View (if exists) with the same name.

                S Offline
                S Offline
                Sarvan AL
                wrote on last edited by
                #7

                Hi Russell, Thanks a lot for your great suggestion. Sarvan AL

                R 1 Reply Last reply
                0
                • S Sarvan AL

                  Hi Russell, Thanks a lot for your great suggestion. Sarvan AL

                  R Offline
                  R Offline
                  Russell
                  wrote on last edited by
                  #8

                  :rose:

                  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