7-tool bar programming and status bar Programming

Source: Internet
Author: User

First, there are two ways to create a toolbar in MFC::

The steps for the first method are as follows:

(1) Create toolbar resources. This is done in the IDE resource editor.

(2) construct a ctoolbar object.

(3) Call the CREATE () function or createex () function to create a Windows toolbar and associate it with the created ctoolbar object. (Two create functions are member functions of ctollbar ). Prototype:

 
Bool create (cwnd * pparentwnd, DWORD dwstyle = ws_child | ws_visible | cbrs_top, uint nid = portable); bool createex (cwnd * pparentwnd, DWORD dwctrlstyle = tbstyle_flat, DWORD dwstyle = ws_child | ws_visible | cbrs_align_top, crect rcborders = crect (0, 0, 0, 0), uint nid = afx_idw_toolbar );

For parameter meanings, refer to msdn;

(4) Call the loadtoolbar function to load toolbar resources.

The following is the oncreate function in the cmainframe class:

 
If (! M_newtoolbar.createex (this, tbstyle_flat, ws_child | ws_visible | cbrs_right | cbrs_gripper | cbrs_tooltips | cbrs_flyby | cbrs_size_dynamic) |! M_newtoolbar.loadtoolbar (idr_toolbar1) {trace0 ("failed to create Toolbar \ n"); Return-1; // fail to create}

Method 2: Create a toolbar:

(1) construct a ctoolbar object;

(2) Call the createex or create function to create a toolbar and associate it with the created ctoolbar object.

(3) Call the loadbitmap function to load the image bitmap containing the toolbar buttons.

(4) Call the serbuttons function to set the button style. prototype:

 
Bool setbuttons (const uint * lpidarray, int nidcount );

The following describes how to create a toolbar in MFC. In the oncreate function of the cmainframe class, call the oncreateex () function of the ctoolbar class to create a toolbar, and then call loadtoolbar () the function loads toolbar resources, and then the oncreate function of the cmainframe class calls the member function enabledocking () of the parent class ccontrolbar of the toolbar object to set the tool bar's Dock position. The optional values are as follows:

cbrs_align_top allows docking at the top of the client area.
cbrs_align_bottom allows docking at the bottom of the client area.
cbrs_align_left allows docking on the left side of the client area.
cbrs_align_right allows docking on the right side of the client area.
cbrs_align_any allows docking on any side of the client area.
cbrs_float_multi allows multiple control bars to be floated in a single mini-frame window.

Next, the oncreate function of the cmainframe class calls an enabledocking function,The enabledocking () function previously called for the first time is a member function of the tool's junlang object (in the parent class). The purpose is to allow toolbar objects to be docked, the second call is the enabledocking () member function of the cframewnd object, so that the main frame window can be docked.The drop-down table is composed of the first five items in the table.

Hide the display toolbar:

 
M_newtoolbar.showwindow (sw_hide); m_newtoolbar.showwindow (sw_show );

Next is the status bar programming:

We can see that the oncreate function of cmainframe already has the status bar responseCode, Indicator []. If you want to add information about the status bar in the array, you can add an ids_timer (ID of the custom status bar item) to the string table and add it to the array.

 
If (! M_wndstatusbar.create (this) |! M_wndstatusbar.setindicators (indicators, sizeof (indicators)/sizeof (uint) {trace0 ("failed to create status bar \ n"); Return-1; // fail to create}

Static uint indicators [] = // indicator Array {id_separator, // status line indicatorids_timer, ids_progress, id_indicator_caps, id_indicator_num, handler ,};

Of course, you can add some status display controls in the status bar and the following status display controls! For example, the cprogressctrl control.

Remember the most important thing-msdn!

Keep a record of what you have learned !!! If I am a snail bot, I can only climb up slowly!

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.