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