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.
 
 

你可能感兴趣的:(C++,Microsoft,mfc,vc++,工具栏)