chilli 的 mfc指標的獲取
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://忽略透明子視窗
獲取工具條的指標
在預設狀態下,有乙個預設的工具條afx_idw_*******,我們可以根據相應的id去獲取工具條指標,方法如下:
c******** p*******=(c********)afxgetmainwnd()->getdescendantwindow(afx_idw_*******);
是不是很簡單?
獲取狀態條的指標
在預設狀態下,有乙個預設的狀態條afx_idw_status_bar,我們自然也可以根據相應的id去獲取狀態條指標,方法如下:
cstatusbar* p*******=(cstatusbar*)afxgetmainwnd()->getdescendantwindow(afx_idw_status_bar);
這裡有兩種方法。
一、呼叫cwnd: : getdlgitem,獲取乙個cwnd*指標呼叫成員函式。例如,我們想獲取cbutton指標,方法如下:
cbutton* pbutton=(cbutton*) getdlgitem (idc_mybutton);
二、可以使用classwizard將控制項和成員變數聯絡起來。在classwizard中簡單地選擇member variables標籤,然後選擇add variable …按鈕。如果在對話資源編輯器中,按下ctrl鍵並雙擊控制項即可轉到add member variable對話。
我們可以利用文件類的成員函式getfirstview()和getnextview()遍歷檢視。
其實,在檢視類中有乙個現成的成員函式供我們使用,那就是:getdocument();利用它我們可以很容易的得到文件類指標,我們先看一下 getdocument()函式的實現:
ccolorbuttondoc* ccolorbuttonview::getdocument()
這裡實際上是將m_pdocument強制轉換成ccolorbuttondoc*,也就是我們想要的。
這裡我們可以利用getactive***xx()去掉用當前啟用的文件和檢視:
cmydoc* pdoc=(cmydoc*)getactivedocument();
cmyview* pview=(cmyview*)getactiveview();
引用MFC指標的獲取 一
2 獲取主框架指標 或者 cmainframe pmainframe cmainframe afxgetmainwnd 獲取選單指標 cmenu pmenu afxgetmainwnd getmenu 獲取工具欄 狀態列指標 主框架中可以直接使用m wnd m wndstatusbar 其他 c p...
mfc指標獲取
1 獲取應用程式指標2 獲取主框架指標或者 cmainframe pmainframe cmainframe afxgetmainwnd 獲取選單指標 cmenu pmenu afxgetmainwnd getmenu 獲取工具欄 狀態列指標 主框架中可以直接使用m wnd m wndstatusb...
MFC中獲取指標
獲取工具條的指標 在預設狀態下,有乙個預設的工具條afx idw 我們可以根據相應的id去獲取工具條指標,方法如下 c p c afxgetmainwnd getdescendantwindow afx idw 是不是很簡單?獲取狀態條的指標 在預設狀態下,有乙個預設的狀態條afx idw stat...