MDIFrameWnd類GetActiveFrame和MDIGetActive的區別

來源:互聯網
上載者:User

查看msdn可以知道GetActiveFrame其實是CFrameWnd的方法,是MDIFrameWnd繼承而來的方法,在msdn中其說明為:

CFrameWnd::GetActiveFrame  

virtual CFrameWnd* GetActiveFrame( );

Return Value

A pointer to the active MDI child window. 

If the application is an SDI application, or the MDI frame window has no active document, the implicit
this pointer will be returned.

Remarks

  If there is no active MDI child or the application is a single document interface (SDI), the implicit
this pointer is returned.

    從說明中我們可以看出,如果改CFrameWnd對象是MDI frame window那麼並且其有active document,那麼該方法的傳回值應該是active MDI child window。這是官方的說明。

我們在看一下MDIGetActive方法的說明:

CMDIFrameWnd::MDIGetActive


CMDIChildWnd* MDIGetActive(   BOOL* pbMaximized = NULL ) const;
Parameters
     
pbMaximized

A pointer to a BOOL return value. Set to TRUE on return if the window is maximized; otherwise FALSE.

Return Value

A pointer to the active MDI child window.

    從上述說明中我們可以看出MDIGetActive是CMDIChildWnd的方法,不是從CFrameWnd繼承而來的,在當前的Frame對象是CMDIFrameWnd對象的話而且有Active document的話,則二者應該是沒有區別的。

   但實際情況是否如此呢?至少我今天的經驗告訴我,不是如此。還是那個影像處理演算法架構的問題,昨天將RTTI做好之後,今天加進去了。但是其中在調用的時候出現了問題,由於訊息響應是在一LeftPanel中,不是在Doc中間,所以需要從CAlgorithDialog中間擷取Doc對象,下面是我的兩種擷取方式:

方法一:

  

CMainFrame* pWnd=(CMainFrame*)AfxGetMainWnd();CImgPlatformDoc* pDoc=(CImgPlatformDoc*)pWnd->MDIGetActive()->GetActiveView()->GetDocument();

方法二:

CMainFrame* pWnd=(CMainFrame*)AfxGetMainWnd();//CImgPlatformDoc* pDoc=(CImgPlatformDoc*)pWnd->MDIGetActive()->GetActiveView()->GetDocument();CImgPlatformDoc* pDoc=(CImgPlatformDoc*)pWnd->GetActiveFrame()->GetActiveView()->GetDocument();

   你會發現第二種方法擷取的pDoc實際上是一個NULL值。今天下午在這個問題上犯困了很久,因為一直沒有辦法擷取到Doc對象,一直覺得很奇怪,各種手段都用上了,包括髮送自訂訊息到CMainFrame中,從CMainFrame中調用Doc對象進行處理,但是發現擷取的DOC對象一直是NULL,因為擷取GetActiveFrame的方法一直沒有變,不要和我說你直接用GetActiveDocument方法來擷取DOC對象,我也嘗試過,發現和第二種方法一樣也是空。

    到目前為止還沒有找個這兩者之間到底有什麼區別,看到網上很多人說值CMainFrame中直接用GetActiveDocument就可以擷取當前Active的DOC對象了,我表示很懷疑,因為確實會有傳回值,但是你查看對象資料就會探索資料時不對的,而且返回的DOC對象的地址其實是0x00000000也就是說是一個NULL對象。

    希望有瞭解這個問題的同學給我講解一下這個問題吧。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.