2009. 1. 16. 16:19
CWnd::GetCurrentMessage : 현재 메시지 핸들러가 처리하고 있는 MSG 정보 가져오기
2009. 1. 16. 16:19 in 3. Implementation/MFC
CWnd::GetCurrentMessage
This method obtains a pointer to the MSG structure that contains the message the window is currently processing.
static const MSG* PASCAL GetCurrentMessage( );
Return Value
Returns a pointer to the MSG structure that contains the message the window is currently processing. Should only be called when in an OnMessage handler.
Remarks
This method returns a pointer to a MSG structure. In Windows CE, the time member of this structure contains the system time at which CWnd::GetCurrentMessage is called, rather than the time at which the message was posted.
// The following example toggles two views in a single document // interface (SDI) frame window. A design decision must be made about // whether to leave the inactive view connected to the document, // allowing the inactive view to continue receiveing OnUpdate // notifications from the document. It is often desirable to // keep the inactive view continuously in synchronization with the // document, even though it is inactive. However, doing so incurs a // performance cost,as well as the programming cost of implementing // OnUpdate hints. It may be less expensive, in terms of performance and // programming,to re-sync the inactive view with the document only when it // is reactivated. The following example illustrates the latter approach, // by reconnecting the newly active view and disconnecting the newly // inactive view, through calls to CDocument::AddView and RemoveView. BOOL CMainFrame::OnViewChange(UINT nCmdID) { CView* pViewAdd; CView* pViewRemove; CDocument* pDoc = GetActiveDocument(); UINT nCmdID; nCmdID = LOWORD(GetCurrentMessage()->wParam); if((nCmdID == ID_VIEW_VIEW1) && (m_currentView == 1)) return; if((nCmdID == ID_VIEW_VIEW2) && (m_currentView == 2)) return; if (nCmdID == ID_VIEW_VIEW2) { if (m_pView2 == NULL) { m_pView1 = GetActiveView(); m_pView2 = new CMyView2; // If OnSize has been overridden in CMyView2 // and GetDocument() is used in this override it can // cause assertions and, if the assertions are ignored, // cause access violations. m_pView2->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, rectDefault, this, AFX_IDW_PANE_FIRST + 1, NULL); } pViewAdd = m_pView2; pViewRemove = m_pView1; m_currentView= 2; } else { pViewAdd = m_pView1; pViewRemove = m_pView2; m_currentView= 1; } // Set the child identifier of the active view to AFX_IDW_PANE_FIRST, // so that CFrameWnd::RecalcLayout will allocate to this // first pane, that portion in a client area of the frame window that is // not allocated to control bars. Set the child identifier of the // other view to anything besides AFX_IDW_PANE_FIRST; this // example switches the child identifiers of the two views. int nSwitchChildID = pViewAdd->GetDlgCtrlID(); pViewAdd->SetDlgCtrlID(AFX_IDW_PANE_FIRST); pViewRemove->SetDlgCtrlID(nSwitchChildID); // Show the newly active view and hide the inactive view. pViewAdd->ShowWindow(SW_SHOW); pViewRemove->ShowWindow(SW_HIDE); // Connect the newly active view to the document and // disconnect the inactive view. pDoc->AddView(pViewAdd); pDoc->RemoveView(pViewRemove); SetActiveView(pViewAdd); RecalcLayout(); } |
출처 : MSDN