獲得父視窗指標 獲得MFC視窗其它類指標的方法

2021-04-21 07:43:44 字數 2735 閱讀 4842

獲得cmainframe:

-在cchildframe中可用getparentframe()

-在其它類中用afxgetmainwnd()

獲得cchildframe:

-在cview中用getparentframe()

-在cmainframe中用mdigetactive()或getactiveframe()

-在其它類中用afxgetmainwnd()->mdigetactive()或afxgetmainwnd()->getactiveframe()

獲得cdocument:

-在cview中用getdocument()

-在cchildframe中用getactiveview()->getdocument()

-在cmainframe中用

-if sdi:getactiveview()->getdocument()

-if mdi:mdigetactive()->getactiveview()->getdocument()

-在其它類中

-if sdi:afxgetmainwnd()->getactiveview()->getdocument()

-if mdi:afxgetmainwnd()->mdigetactive()->getactiveview()->getdocument()

獲得cview:

-在cdocument中 position pos = getfirstviewposition();getnextview(pos)

-在cchildframe中 getactiveview()

-在cmainframe中

-if sdi:getactiveview()

-if mdi:mdigetactive()->getactiveview()

-在其它類中

-if sdi:afxgetmainwnd()->getactiveview()

-if mdi:afxgetmainwnd()->mdigetactive()->getactiveview()

不過要注意在doc中要取得view的指標c*view要注意類c*view宣告的問題,

因為預設情況下,mfc在*view.h中已經包含了*doc.h,如果在*doc.h中包含

*view.h,就會引起巢狀包含問題,這樣要在*doc.h中加入 class c*view;

而在*doc.cpp中加入 #include "*view.h"

// 方便我一直專門操作的說:)

// 我先拋塊磚,有玉的砸過來!

2。通過afxgetmainwnd()得到主視窗;

3。通過cmdiframewnd::getactiveframe得到當前活動視窗;

4。通過getnextwindow()遍例所有的子視窗;(如果要得到你想要的子視窗,可以通過特定的成員變數來標誌);

6。通過cdoctemplate::getfirstdocposition()以及cdoctemplate的getnextdoc()組合來遍歷所有的該模板的文件物件,並用cdocument::getdoctemplate()來得到文件模板,用cdocment::gettitle() 或者getpathname()來判斷當前的文件是哪個。

7。通過cdocuemt的getfirstviewpositon()以及getnextview()來遍歷檢視物件,一般通過訪問view的成員變數來區別各個檢視;通過cview::getdocument()來得到文件物件;

8。frame->view: 通過getactiveview方法;

9。frame->doc:通過getactivedocument();

10。view->frame:getparentframe();

11。view->doc:getdocuemt()//前面已經說了。

12。doc->view:前面說了;

13。doc->frame:不知道有沒有很直接的方法。

mfc應用程式中指標的使用

1) 在view中獲得doc指標

3) 在view中獲得mainframe指標

4) 獲得view(已建立)指標

5) 獲得當前文件指標

6) 獲得狀態列與工具欄指標

7) 獲得狀態列與工具欄變數

8) 在mainframe獲得選單指標

9) 在任何類中獲得應用程式類

10) 從文件類取得檢視類的指標(1)

12) 從文件模板獲得文件類指標

13) 在文件類中獲得文件模板指標

14) 從文件類取得檢視類的指標(2)

15) 從乙個檢視類取得另一檢視類的指標

1) 在view中獲得doc指標 cyousdidoc *pdoc=getdocument();乙個視只能有乙個文

檔。 也可以: cmainframe *pmain =(cmainframe *)afxgetmainwnd();

cyouview *pview=(cyouview *)pmain->getactiveview();

5) 獲得當前文件指標 cdocument * pcurrentdoc =(cframewnd *)m_pmainwnd->getactivedocument();

6) 獲得狀態列與工具欄指標 cstatusbar * pstatusbar=(cstatusbar *)afxgetmainwnd()->getdescendantwindow(afx_idw_status_bar);

MFC獲得主視窗和父視窗指標

vc 中有關控制代碼和指標及其轉換 1.mfc視窗的控制代碼和指標的轉換 1 一般視窗物件都會有乙個其對應的控制代碼變數,所以我們可以取此物件的m hwnd屬性來得到控制代碼。2 使用getsafehwnd函式取得程式所在視窗類的控制代碼 3 使用fromhandle函式來通過控制代碼得到其想要的指...

獲得視窗並列舉其子視窗

zzz可以呼叫函式findwindow 視窗類名,視窗標題 獲得視窗的控制代碼,然後呼叫enumchildwindows 父視窗,函式名,引數 來獲得父視窗下的子視窗的控制代碼,實現如下 include windows.h bool callback enumchildproc hwnd hwnd,...

子視窗獲得父視窗得window

我們從乙個介面跳轉至另乙個介面,我們需要知道第乙個介面得使用者是誰,他的使用者放在window.configuration.currentuser 裡面,我們無法開發父頁面,因為父頁面是其他得系統,那麼我們子頁面怎麼獲得人員呢?父頁面狀態 父頁面得繫結值是這樣得,子頁面是我們二次開發得頁面 這裡就遇...