The vc ++ single-document program adds a window movement event (not a size change) to realize the accompanied movement of sub-Windows.

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.