破晓和拂晓的区别:vc++编程问题

来源:百度文库 编辑:中科新闻网 时间:2024/04/29 10:11:13
AfxGetMainWnd()是什么?
能能给出具体的几个应用例子吗?
摆脱各位大虾?
GetActiveView()又是什么?
能能给出具体的几个应用例子吗?
摆脱各位大虾?

AfxGetMainWnd()这个函数是用来获得主窗口的。在MFC中经常要修改主窗口的属性,所以特别提供了这个函数。还有一些Afx开头的函数,也都非常有用。
MSDN中说明:
AfxGetMainWnd
CWnd* AfxGetMainWnd( );

Return Value

If the server has an object that is in-place active inside a container, and this container is active, this function returns a pointer to the frame window object that contains the in-place active document.

If there is no object that is in-place active within a container, or your application is not an OLE server, this function simply returns the m_pMainWnd of your application object.

If AfxGetMainWnd is called from the application's primary thread, it returns the application's main window according to the above rules. If the function is called from a secondary thread in the application, the function returns the main window associated with the thread that made the call.

Remarks

If your application is an OLE server, call this function to retrieve a pointer to the active main window of the application instead of directly referring to the m_pMainWnd member of the application object.

If your application is not an OLE server, then calling this function is equivalent to directly referring to the m_pMainWnd member of your application object.

CFrameWnd::GetActiveView
CView* GetActiveView( ) const;

Return Value

A pointer to the current CView. If there is no current view, returns NULL.

Remarks

Call this member function to obtain a pointer to the active view (if any) attached to a frame window (CFrameWnd).

This function returns NULL when called for an MDI main frame window (CMDIFrameWnd). In an MDI application, the MDI main frame window does not have a view associated with it. Instead, each individual child window (CMDIChildWnd) has one or more associated views. The active view in an MDI application can be obtained by first finding the active MDI child window and then finding the active view for that child window. The active MDI child window can be found by calling the function MDIGetActive or GetActiveFrame as demonstrated in the following:

CMDIFrameWnd *pFrame =
(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;

// Get the active MDI child window.
CMDIChildWnd *pChild =
(CMDIChildWnd *) pFrame->GetActiveFrame();

// or CMDIChildWnd *pChild = pFrame->MDIGetActive();

// Get the active view attached to the active MDI child
// window.
CMyView *pView = (CMyView *) pChild->GetActiveView();