In the past two days, a program will generate several small windows in the CView of a single document, but these small windows will move as the window moves. At the beginning, I tried the OnSize () event, however, OnSize () only responds to window size changes and does not respond to moving events. Then I tried OnMove again, but this event can only respond in the CMainFrame. This requires passing the message to the CView. I wanted to manually create a message, however, after reading a lot of information, I was still confused in the cloud. Then I suddenly thought that I could manually send the WM_SIZE message to the view, so I set the message sending code in the OnMove event in the CMainFrame, everything is done. The Code is as follows:
// After the OnMove event is returned in the main framework, the WM_SIZE message is sent to the active View.
1 void CMainFrame: OnMove (int x, int y) 2 {3 CFrameWnd: OnMove (x, y); 4 CView * active = GetActiveView (); // obtain the current video class pointer 5 if (active! = NULL) 6 active-> PostMessage (WM_SIZE, x, y); 7 // TODO: Add your message handler code here 8}
1 // Response Message WM_SIZE in View Class 2 void CKkView: OnSize (UINT nType, int cx, int cy) 3 {4 CView: OnSize (nType, cx, cy); 5 // TODO: Add your message handler code here 6 // move the information subwindow m_ctrlMapX.m_hWnd! = NULL 7 8 CRect clientRect; 9 GetClientRect (clientRect); 10 ClientToScreen (clientRect); 11 CRect msgRect; 12 msgDlg. getWindowRect (msgRect); 13 msgDlg. moveWindow (clientRect. right-msgRect.Width (), clientRect. top, msgRect. width (), 25); 14}
I finally solved the problem one afternoon!