轉)VC獲取各類指標

2021-09-30 16:15:34 字數 2799 閱讀 6408

3、獲取選單指標

cmenu* pmenu = afxgetmainwnd()->getmenu();

4、獲取工具欄、狀態列指標

主框架中可以直接使用m_wnd*******、m_wndstatusbar

其他:

c******** p******* = (c********)afxgetmainwnd()->getdescendantwindow(afx_idw_*******);

cstatusbar* pstatusbar = (cstatusbar*)afxgetmainwnd()->getdescendantwindow(afx_idw_status_bar);

5、獲取控制項指標

先用 getdlgitem() 再轉換,如:

cbutton* pbutton = (cbutton*)getdlgitem(idc_mybutton);

6、獲取文件、檢視指標

sdi:

cmainframe* pmainframe = (cmainframe*)afxgetmainwnd();

cyourdoc* pdoc = (cyourdoc*)pmainframe->getactivedocument();

cyourview* pview = (cyourview*)pmainframe->getactiveview();

mdi:

cmainframe* pmainframe = (cmainframe*)afxgetmainwnd();

cchildframe* pchildframe = (cchildframe*)pmainframe->getactiveframe();

cyourdoc* pdoc = (cyourdoc*)pchildframe->getactivedocument();

cyourview* pview = (cyourview*)pchildframe->getactiveview();

7、文件、檢視

從檢視獲取文件指標:

cyourdoc* pdoc = getdocument();

從文件獲取檢視指標:

利用成員函式 getfirstviewposition() 和 getnextview() 遍歷

virtual position getfirstviewposition() const;

virtual cview* getnextview(position& rposition) const;

sdi:

cyourview* pview;

position pos = getfirstviewposition();

pview = getnextview(pos);

mdi:

定義函式

cview* cyourdoc::getview(cruntimeclass* pclass)

if(!pview->iskindof(pclass))

return pview;

} 使用如下:

cyourview* pview=(cyourview*)getview(runtime_class(cyourview));

8、文件模版、文件

從文件獲取文件模版指標:

cdoctemplate* getdoctemplate() const;

從文件模版獲取文件指標:

viaual position getfirstdocposition( ) const = 0;

visual cdocument* getnextdoc(position & rpos) const = 0;

9、獲取分割檢視中各個檢視的指標

主框架中定義:csplitterwnd m_wndsplitter;

定義兩個view類:cview1、cview2

框架類中過載:

bool cmainframe::oncreateclient(lpcreatestruct, ccreatecontext* pcontext)

獲取分割檢視指標

cview1* pview1 = (cview1*)m_wndsplitter.getpane(0,0);

cview2* pview2 = (cview2*)m_wndsplitter.getpane(1,0);

10、通過滑鼠獲得子視窗指標

cwnd* childwindowfrompoint(point point) const;

cwnd* childwindowfrompoint(point point,uint nflags) const;

用於確定包含指定點的子視窗

如果指定點在客戶區之外,函式返回null;

如果指定點在客戶區內,但是不屬於任何乙個子視窗,函式返回該cwnd的指標;

如果有多個子視窗包含指定點,則返回第乙個子視窗的指標。

還要注意的是,該函式返回的是乙個偽視窗指標,不能將它儲存起來供以後使用。

對於第二個引數nflags有幾個含義:

cwp_all             file://不忽略任何子視窗

cwp_skipnivsible    file://忽略不可見子視窗

cwp_skipdisabled    file://忽略禁止的子視窗

cwp_skipransparent file://忽略透明子視窗

在獲取視類的指標時,需要在需要獲取類的cpp檔案前面加入#include "***view.h",這樣編譯時會報錯,解決方法是在視類的cpp檔案前面加入#include "***doc.h"

vc各類之間的呼叫函式總結

在新建類中獲取其他的類 afxgetinstancehandle get frame view document 獲取檢視 sdi afxgetmainwnd getactiveview getdocument mdi afxgetmainwnd mdigetactive getactiveview...

VC 從View類獲取各種指標程式設計例項

新建乙個多文件工程 名為getptrdemo 在視類ondraw函式,獲取其他類指標 然後進行一些操作 首先獲取應用程式類指標 可以獲取到 然後利用它輸出程式名 然後獲取主框架類指標 直接在視類ondraw函式加入如下 編譯會出現 error c2065 cmainframe undeclared ...

MFC 各類間指標的獲得

1 在view中獲得doc指標 3 在view中獲得mainframe指標 4 獲得view 已建立 指標 5 獲得當前文件指標 6 獲得狀態列與工具欄指標 7 獲得狀態列與工具欄變數 8 在mainframe獲得選單指標 9 在任何類中獲得應用程式類 10 從文件類取得檢視類的指標 1 12 從文...