Create a cool tool bar similar to ie4 by VC

Source: Internet
Author: User
Tags button attributes

Zhong jiansong (jonson@public.cs.hn.cn)
Changsha Telecom bureau computer center 410007

There are many ways to create a tool bar with VC. This article provides a tool bar similar to ie4.0. When you can move the mouse, the icon changes to color. Several tool bars can be suspended at the position of the tool bar. For detailed principles, see the procedure.
The procedure is as follows:
1. Run Appwizard, select single document, and select the default settings for others.
2. Click Insert resource and add two bitmaps, which are defined as idb_coldtoolbar and idb_hottoolbar.
3. Add member variables to cmainframe:
Crebar m_wndrebar;
Ccomboboxex m_wndaddress;
4. Modify the cmainframe: oncreate (maid) function as follows:
Int cmainframe: oncreate (maid)
{
Cimagelist IMG;
Cstring STR;

If (cframewnd: oncreate (lpcreatestruct) =-1)
return-1;
If (! M_wndtoolbar.createex (this, tbstyle_flat, ws_child extends ws_visible extends cbrs_top
extends cbrs_gripper extends cbrs_tooltips extends cbrs_flyby extends cbrs_size_dynamic ))
{< br> trace0 ("failed to create Toolbar \ n");
return-1; // fail to create
}

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

M_wndtoolbar.gettoolbarctrl (). setbuttonwidth (50,150); // you can specify the size of a toolbar.
M_wndtoolbar.gettoolbarctrl (). setextendedstyle (tbstyle_ex_drawddarrows );

// Create an icon list when you move the cursor over
IMG. Create (idb_hottoolbar, 22, 0, RGB (255, 0,255); m_wndtoolbar.gettoolbarctrl (). sethotimagelist (& IMG );
IMG. Detach ();
// Create a no-focus icon list
IMG. Create (idb_coldtoolbar, 22, 0, RGB (255, 0,255 ));
M_wndtoolbar.gettoolbarctrl (). setimagelist (& IMG );
IMG. Detach ();
M_wndtoolbar.modifystyle (0, tbstyle_flat extends tbstyle_transparent );
// Set the number of icons to be displayed, which can be modified as needed
M_wndtoolbar.setbuttons (null, 9 );

// Set the icon button attributes one by one
/* Setbuttoninfo (INT nindex, uint NID, uint nstyle, int iimage); the parameters are as follows:
Nindex: index value of the icon button
NID: The resource ID associated with the icon button
Nstyle: icon button style
The following are common examples:
Tbbs_button standard button
Tbbs_separator Separator
Tbstyle_dropdown button with the down arrow
Iimage: The image index value in the created imagelist.
*/

M_wndtoolbar.setbuttoninfo (0, id_file_new, tbstyle_button, 0 );
M_wndtoolbar.setbuttontext (0, "rollback ");
M_wndtoolbar.setbuttoninfo (1, id_file_open, tbstyle_button, 1 );
M_wndtoolbar.setbuttontext (1, "Forward ");
M_wndtoolbar.setbuttoninfo (2, id_file_save, tbstyle_button extends tbbs _ separator, 2 );
M_wndtoolbar.setbuttontext (2, "stop ");
M_wndtoolbar.setbuttoninfo (3, id_file_print_setup, tbstyle_button define tbstyle_dropdown, 3 );
M_wndtoolbar.setbuttontext (3, "Print Settings ");

Crect recttoolbar;

// Set the toolbar size
M_wndtoolbar.getitemrect (0, & recttoolbar );
M_wndtoolbar.setsizes (recttoolbar. Size (), csize (30,20 ));

// Create
If (! M_wndaddress.create (cbs_dropdown into ws_child, crect (0, 0,200,120), this, afx_idw_toolbar + 1 ))
{
Trace0 ("failed to create ComboBox \ n ");
Return-1; // fail to create
}

Comboboxexitem item;

Item. Mask = cbeif_text;
Item. iItem =-1;
Item. psztext = "jiansong ideology ";
M_wndaddress.insertitem (& item );

If (! M_wndrebar.create (this ))
{
Trace0 ("failed to create rebar \ n ");
Return-1; // fail to create
}

// Add the toolbar and the generated input box to the crebar object, which is displayed in the toolbar area.
M_wndrebar.addbar (& m_wndtoolbar );
M_wndrebar.addbar (& m_wndaddress, "Address", null, rbbs_fixedbmp extends rbbs_break );

Return 0;
}

At this point, runProgram, You can see a program similar to ie4.0. However, the drop-down icon button does not display the drop-down menu and does not respond to messages in the input box. Continue to modify the program as follows:

5. create menu idr_print_popup
6. in mainframe. h add
afx_msg void ondropdown (nmhdr * pnotifystruct, lresult * presult);
in mainframe. message_map in CPP is added to message ing
on_notify (tbn_dropdown, afx_idw_toolbar, ondropdown)
and processing function body:
void cmainframe: ondropdown (nmhdr * pnotifystruct, lresult * presult)
{< br> // This function handles the dropdown menus from the toolbar
nmtoolbar * pnmtoolbar = (nmtoolbar *) ppolicystruct;
crect rect;

// translate the current toolbar item rectangle into screen coordinates
// so that we'll know where to pop up the menu
m_wndtoolbar.gettoolbarctrl (). getrect (pnmtoolbar-> iItem, & rect);
rect. top = rect. bottom;
:: clienttoscreen (pnmtoolbar-> HDR. hwndfrom, & rect. topleft ();
If (pnmtoolbar-> iItem = id_file_print_setup)
{< br> cmenu menu;
cmenu * ppopup;

// The font popup is stored in a resource
Menu. loadmenu (idr_print_popup );
Ppopup = menu. getsubmenu (0 );
Ppopup-> trackpopupmenu (tpm_leftalign effectpm_leftbutton, rect. Left, rect. Top + 1, afxgetmainwnd ());
}
* Presult = tbddret_default;
}

7. process the response to the combox. Here, only messages with changed content are processed. To add other processes, see message ing of combo box handlers.
Add afx_msg void onnewaddress () to mainframe. h ();
Add message ing to message_map in mainframe. cpp.
On_cbn_selendok (afx_idw_toolbar + 1, onnewaddress)
Add function body
Void cmainframe: onnewaddress ()
{
Cstring STR;
ShellExecute (null, "open", "http://jonson.126.com", null, null, sw_show );
}

AttachedSource codeExample.

Reference announcement address: http://blog.csdn.net/jonson/services/trackbacks/2699.aspx

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.