日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > c/c++ >内容正文

c/c++

VC++ 从View类获取各种指针编程实例

發(fā)布時(shí)間:2025/4/14 c/c++ 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 VC++ 从View类获取各种指针编程实例 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

新建一個(gè)多文檔工程;名為GetPtrDemo;

在視類OnDraw函數(shù),獲取其他類指針;然后進(jìn)行一些操作;

首先獲取應(yīng)用程序類指針;可以獲取到;然后利用它輸出程序名;

? ? CGetPtrDemoApp* pApp=(CGetPtrDemoApp*)AfxGetApp();
?? ?pDC->TextOut(100,10, pApp->m_pszAppName);

然后獲取主框架類指針;直接在視類OnDraw函數(shù)加入如下代碼,編譯會(huì)出現(xiàn)

error C2065: 'CMainFrame' : undeclared identifier;

因?yàn)橐话悴恍枰苯釉谝曨惈@取主框架指針;? ??
?? ?CMainFrame* pMainFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
?? ?pDC->TextOut(100,40, (void*)pMainFrame);
?? ?CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
?? ?

獲取菜單指針;輸出指針的值;獲取第一個(gè)菜單的文本,然后輸出;可以;
?? ?CMenu* pMenu = AfxGetMainWnd()->GetMenu();
?? ?pDC->TextOut(100,40, (char*)pMenu);
?? ?CString strmenu1;
?? ?pMenu->GetMenuString(1,strmenu1,MF_BYPOSITION);
?? ?pDC->TextOut(100,70, strmenu1);

?

獲取工具條指針;然后獲取第一個(gè)按鈕的文本,設(shè)置第四個(gè)按鈕的文本;獲取不到第一個(gè)按鈕的文本,設(shè)置也無(wú)效;可能是按鈕風(fēng)格方面的一些問(wèn)題;下回再搞;

?? ?CToolBar* pToolBar = (CToolBar*)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_TOOLBAR);
?? ?CString strtooltext;
?? ?pToolBar->GetButtonText(1,strtooltext);
?? ?pToolBar->SetButtonText(4,"我自己改的");
?? ?pDC->TextOut(100,100, strtooltext);

?? ?//CStatusBar* pStatusBar = (CStatusBar*)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_STATUS_BAR);

獲取文檔指針;視類OnDraw函數(shù)已經(jīng)具有該指針;可直接使用;輸出文檔標(biāo)題;

?? ?pDC->TextOut(100,150,pDoc->GetTitle());

OnDraw函數(shù)如下;

void CGetPtrDemoView::OnDraw(CDC* pDC) {CGetPtrDemoDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);// TODO: add draw code for native data hereCGetPtrDemoApp* pApp=(CGetPtrDemoApp*)AfxGetApp();pDC->TextOut(100,10, pApp->m_pszAppName);//CMainFrame* pMainFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);//pDC->TextOut(100,40, (void*)pMainFrame);//CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();CMenu* pMenu = AfxGetMainWnd()->GetMenu();pDC->TextOut(100,40, (char*)pMenu);CString strmenu1;pMenu->GetMenuString(1,strmenu1,MF_BYPOSITION);pDC->TextOut(100,70, strmenu1);CToolBar* pToolBar = (CToolBar*)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_TOOLBAR);CString strtooltext;pToolBar->GetButtonText(1,strtooltext);pToolBar->SetButtonText(4,"我自己改的");pDC->TextOut(100,100, strtooltext);//CStatusBar* pStatusBar = (CStatusBar*)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_STATUS_BAR);pDC->TextOut(100,150,pDoc->GetTitle()); }

運(yùn)行截圖:

總結(jié)

以上是生活随笔為你收集整理的VC++ 从View类获取各种指针编程实例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。