1.在resourceview裡加入*******資源,命名idr_*******1
2.在主程式的.h檔案中加入變數:
c******* m_wnd*******;//新增工具欄
cimagelist m_il*******;//使工具欄圖示顯示256色
3.在主程式的.h檔案中加入函式:
afx_msg bool ontooltiptext(uint nid, nmhdr* pnmhdr, lresult* presult);//使工具欄顯示提示資訊
4.在主程式的.h檔案中的begin_message_map(cdetectordlg, cdialog)函式裡加入:
on_notify_ex( ttn_needtext, 0, ontooltiptext )//使工具欄顯示提示資訊
5.在主程式的.cpp檔案中,在初始化的地方(oncreate或者oninitdialog)加入:
//新增乙個平面工具欄
if (!m_wnd*******.createex( this,tbstyle_flat , ws_child | ws_visible | cbrs_align_top | cbrs_gripper | cbrs_tooltips,crect(4,4,0,0)) ||!m_wnd*******.load*******(idr_*******1) )
m_wnd*******.showwindow(sw_show);
repositionbars(afx_idw_controlbar_first, afx_idw_controlbar_last, 0);
//使工具欄圖示顯示256色
hbitmap hbm = (hbitmap)::loadimage(afxgetinstancehandle(),
makeintresource(idr_*******1), //載入idb_*******
image_bitmap, //按位圖格式
0,0, // cx,cy
lr_createdibsection | lr_loadmap3dcolors );
cbitmap bm;
bm.attach(hbm);
m_il*******.create(24,24,ilc_color8, 4, 4);
m_il*******.add(&bm,(cbitmap*)null);
m_wnd*******.get*******ctrl().setimagelist(&m_il*******);
6.在主程式的.cpp檔案中編譯函式ontooltiptext//使工具欄顯示提示資訊
bool cdetectordlg::ontooltiptext(uint, nmhdr* pnmhdr, lresult* presult)
if (nid !=
0) //不為分隔符
else
#else
if (pnmhdr->code == ttn_needtexta)
else
#endif
*presult =
0; // 使工具條提示視窗在最上面
::setwindowpos(pnmhdr->hwndfrom, hwnd_top, 0, 0, 0, 0,swp_noactivate| swp_nosize|swp_nomove|swp_noownerzorder);
return
true;
} return
true;
}
7.在resourceview的string資源裡,將工具欄中每個按鈕的id都對應上希望顯示的提示資訊即可,例如:
*******中有一按鈕的id是idc_openfile,希望顯示的提示資訊為「開啟檔案」 那麼,你需要做的就是在string資源中加入一條id同樣是idc_openfile, 內容是: 開啟檔案
在執行的時候,將滑鼠放在按鈕上面就會提示 「開啟檔案」了
這樣就完成了所有的步驟。
WTL對話方塊增加工具條
其實很簡單,就一句話。因為create ctrl是乙個靜態函式 hwnd hwnd cframewindowimplbase create ctrl m hwnd,idr general,false,atl pane style ex 樣式如下,工具條,可以帶下拉列表 具體步驟 1.包含檔案.h i...
在對話方塊中新增狀態條
在對話方塊中新增狀態條 在c 論壇裡,有人曾問怎樣在對話方塊中加狀態條,我愚蠢地答覆,他只要在 dialog 類中加cstatusbar 成員m bar 然後在 oninitdialog 中呼叫m bar.create 就行了。然後有人繼續跟帖,這樣並不湊效,我就親自試了一下,果不料不行。無論如何,...
vc對話方塊中新增工具欄
轉http www.programfan.com blog article.asp?id 27914 1 新增工具欄資源id為idr 2 在對話方塊的類定義中加 c m 3 在oninitdialog中或其它合適的訊息響應中加如下 函式可檢視msdn m create this 建立工具欄 m lo...