Toolbars工具欄

1、工具欄
工具欄的BUTTON分爲Pushbutton和 Check Box Button兩種。Pushbutton是像“新建”、“打開”那種,而Check Box Button是按下去不彈起的那種,例如迅雷中的“下載完畢關鍵”按鈕。
雖然有很多按鈕,但工具欄只有一個BMP資源。用記事本打開.rc文件,可以看到以下定義:
/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//
IDR_MAINFRAME           BITMAP  MOVEABLE PURE   "res\\Toolbar.bmp"
/////////////////////////////////////////////////////////////////////////////
//
// Toolbar
//
IDR_MAINFRAME TOOLBAR DISCARDABLE  16, 15
BEGIN
    BUTTON      ID_FILE_NEW
    BUTTON      ID_FILE_OPEN
    BUTTON      ID_FILE_SAVE
    SEPARATOR
    BUTTON      ID_EDIT_CUT
    BUTTON      ID_EDIT_COPY
    BUTTON      ID_EDIT_PASTE
    SEPARATOR
    BUTTON      ID_FILE_PRINT
    SEPARATOR
    BUTTON      ID_APP_ABOUT
    BUTTON      ID_BUTTON32779
    BUTTON      ID_BUTTON32780
    BUTTON      ID_BUTTON32781
    BUTTON      ID_BUTTON32782
END
從中可以看出,一個按鈕對應一個菜單ID。如果BMP上的按鈕數量超過上面BUTTON的個數,那麼多餘的按鈕將不被顯示。如果某個BUTTON沒有對應一個菜單ID,那最好對應一個快捷鍵。
 
Toolbar Update Command UI Message Handlers
函數CmdUI::Enable(false)控制可按不可按。false--不可按;true---可按。
函數CmdUI::SetCheck(0)控制按下或彈起。0--彈起;1--按下。
 
Locating the Main Frame Window
 
If you want your view class to work in both SDI and MDI applications, you must find the main frame window through the application object. The AfxGetApp global function returns a pointer to the application object. You can use that pointer to get the CWinApp data member m_pMainWnd. In an MDI application, AppWizard generates code that sets m_pMainWnd, but in an SDI application, the framework sets m_pMainWnd during the view creation process. Once m_pMainWnd is set, you can use it in a view class to get the frame's toolbar with statements such as this:
CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
CToolBar* pToolBar = &pFrame->m_wndToolBar;
You'll need to cast m_pMainWnd from CFrameWnd* to CMainFrame*
because m_wndToolBar is a member of that derived class. You'll
also have to make m_wndToolBar public or make your class a friend
of CMainFrame.
You can use similar logic to locate menu objects, status bar objects,
and dialog objects.
In an SDI application, the value of m_pMainWnd is not set when the
view's OnCreate message handler is called. If you need to access the
main frame window in your OnCreate function, you must use the
GetParentFrame function.
 
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章