Graphic example of VC ++ tool bar and status bar Programming

Source: Internet
Author: User

Graphic example of VC ++ tool bar and status bar Programming

Demo project

Http://pan.baidu.com/s/1mh83aru

Graphics folder resources attached to VB6

Http://pan.baidu.com/s/1sl5RmI5

1. Add a toolbar in the dialog box

 

 

For example, insert and edit toolbar resources;

Add it to the header file of the dialog box;

CToolBar m_ToolBar;

 

OnInitDialog () function to add

 

if(!m_ToolBar.CreateEx( this,TBSTYLE_FLAT , WS_CHILD | WS_VISIBLE |CBRS_ALIGN_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS,              CRect(4,4,0,0))||!m_ToolBar.LoadToolBar(IDR_TOOLBAR1) )       {              TRACE0("failedto create toolbar\n");              return FALSE;       }       m_ToolBar.ShowWindow(SW_SHOW);       RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST, 0);

Effect:

 

 

2. Customize the toolbar through the image list

 

 

 

For example, insert the required ico files in the VC resource window and name them separately;

Add in the header file of the dialog box

CToolBar m_ToolBar;
CImageList m_ImageList;

Add the following code to the OnInitDialog () function to associate the image list with the toolbar and display it.

 

M_ImageList.Create (32, 32, ILC_COLOR24 | ILC_MASK,); // Add the icon m_ImageList.Add (AfxGetApp ()-> LoadIcon (dependencies) to the image list; m_ImageList.Add (AfxGetApp () -> LoadIcon (region); m_ImageList.Add (AfxGetApp () -> LoadIcon (IDI_ICONIMPORT); m_ImageList.Add (AfxGetApp ()-> LoadIcon (IDI_ICONEXPORT); UINT array [8]; for (int I = 0; I <8; I ++) // initialize the toolbar ID {if (I = 2 | I = 5) array [I] = ID_SEPARATOR; // 3rd and 6 buttons are separation bars else array [I] = I + 1001;} m_ToolBar.Create (this); m_ToolBar.SetButtons (array, 8 ); // associate the image list m_ToolBar.GetToolBarCtrl (). setImageList (& m_ImageList); m_ToolBar.SetSizes (CSize (50, 60), CSize (32, 32); // set The size of buttons and icons/* The sizeImage parameter must contain thesize, in pixels, of the images in the toolbar's bitmap. the dimensions in sizeButton must besufficient to hold the image plus 7 pixels extra in width and 6 pixels extra inheight. this function also sets the toolbar heightto fit the buttons. * /// set the text m_ToolBar.SetButtonText (0, "user"); m_ToolBar.SetButtonText (1, "set"); m_ToolBar.SetButtonText (3, "query "); m_ToolBar.SetButtonText (4, "record"); m_ToolBar.SetButtonText (6, "import"); m_ToolBar.SetButtonText (7, "Export"); RepositionBars (AFX_IDW_CONTROLBAR_FIRST, limit, 0 );
Effect:

 

 

3. Import the image to generate a toolbar and bind the toolbar to the corresponding items in the menu bar.

 

For example, insert the required ico files in the VC resource window and name them separately. Then insert a menu resource and edit it;

Add in header file

CMenu m_Menu;
CToolBar m_ToolBar;
CImageList m_ImageList;

Add the following code to the OnInitDialog () function, associate the image list with the toolbar, and associate the toolbar with the corresponding menu item ID to share the processing function with the menu item.

m_Menu.LoadMenu(IDR_MENU1);    SetMenu(&m_Menu);        TBBUTTON tbButton[5] = {0};       m_ImageList.Create(32,32, ILC_COLOR32 | ILC_MASK, 0, 0);       m_ImageList.Add(::AfxGetApp()->LoadIcon(IDI_ICON3));       m_ImageList.Add(::AfxGetApp()->LoadIcon(IDI_ICON1));       m_ImageList.Add(::AfxGetApp()->LoadIcon(IDI_ICON4));       m_ImageList.Add(::AfxGetApp()->LoadIcon(IDI_ICON5));       m_ImageList.Add(::AfxGetApp()->LoadIcon(IDI_ICON2));       //m_ToolBar.Create(WS_CHILD| WS_VISIBLE, CRect(0, 0, 0, 0), this, 0);   //m_ToolBar.Create(this,WS_CHILD| WS_VISIBLE,0);   m_ToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP );       m_ToolBar.GetToolBarCtrl().SetImageList(&m_ImageList);       for(int i=0; i< 5; i++)       {              tbButton[i].dwData        = NULL;              tbButton[i].fsState         = TBSTATE_ENABLED;              tbButton[i].fsStyle         = (BYTE)TBSTYLE_FLAT;              tbButton[i].iBitmap        = i;       }       tbButton[0].idCommand= ID_ATTENDANCE_RECORD;       tbButton[1].idCommand= IDM_REQUEST_EMPLOYEE;       tbButton[2].idCommand= IDM_PAYLIP;       tbButton[3].idCommand= IDM_PORTFOLIO;       tbButton[4].idCommand= ID_ABOUT;       m_ToolBar.GetToolBarCtrl().AddButtons(5,tbButton);       m_ToolBar.GetToolBarCtrl().AutoSize();       m_ToolBar.GetToolBarCtrl().SetStyle(TBSTYLE_FLAT| CCS_TOP);

Effect:

 

To associate buttons in the toolbar with menu items, you can also set their IDs to the same ID.

4. Add the status bar. Method 1: add the member variable CStatusBarCtrl m_StatusBar; add it to OnInitDialog ().
M_StatusBar.Create (WS_CHILD | WS_VISIBLE | SBT_OWNERDRAW, CRect (100,200,), this, 0); int strPartDim [3] = {,-1 }; // Number of shards m_StatusBar.SetParts (3, strPartDim); // set the status bar text m_StatusBar.SetText ("column 1", 0, 0); m_StatusBar.SetText ("column 2", 1, 0 ); m_StatusBar.SetText ("column 3", 2, 0); // Add the icon m_StatusBar.SetIcon (1, SetIcon (AfxGetApp ()-> LoadIcon (IDR_MAINFRAME) to the status bar ), FALSE); // indicates the icon in the second column.
Effect:

 

5. Add the status bar. Method 2: add the member variable CStatusBar m_wndStatusBar. Add it to OnInitDialog ().
Static UINT indicators [] = {ID_SEPARATOR, // status line indicator ID_INDICATOR_CAPS, // CAP lock indicator. ID_INDICATOR_NUM, // NUM lock indicator. ID_INDICATOR_SCRL, // SCRL lock indicator .}; if (! M_wndStatusBar.Create (this) |! Outputs (indicators, sizeof (indicators)/sizeof (UINT) {TRACE0 ("Failed to create statusbarn"); return-1; // fail to create} UINT nID; // control the columns m_wndStatusBar.SetPaneInfo (0, nID, SBPS_STRETCH | SBPS_NOBORDERS, 100) in the status bar; // The values returned are values (0, "ready") in nID; values (1, nID, SBPS_NORMAL, 100); m_wndStatusBar.SetPaneText (1, "capital"); Round (2, nID, SBPS_POPOUT, 100); m_wndStatusBar.SetPaneText (2, "Number "); // The third parameter of the SetPaneInfo () function has The following options: // the following indicator styles are supported: // SBPS_NOBORDERS No 3-D border around The pane. // sbps_pout Reverse border so that text "pops out. "// SBPS_DISABLED Do not draw text. // SBPS_STRETCH Stretch pane to fill unused space. only one pane per status bar can have thisstyle. // SBPS_NORMAL No stretch, borders, or pop-out. // ---------------- display the status bar in the dialog box ------------- RepositionBars (AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0 );
Effect:

The icon used is the content in the graphics folder attached to VB6. See the Previous download link;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.