The property settings bar for Visual C + + 2005 Image programming

Source: Internet
Author: User
The toolbox contains the functions of selection, filling, and drawing lines. When using these tools, you need to set the fill style and the size of the line. The property toolbar is implemented for easy user action and easier UI implementation. The main features that the property bar needs to add are 2 static text boxes and 2 combo boxes that display text.

To add a property bar control, you need to first set up four corresponding toolbar buttons in the appropriate location through the resource editor, and you may not find the button's property editor for friends who have not contacted Visual C + + 2005. In Visual C + + 6.0, the Enter (right) pop-up dialog box is set. By default, you can open the Property Settings dialog box to the right of the toolbar. Note the position of the red number in the figure below is where we create the static text box and combo box.


Figure 2-1

Build a Cbasetoolbar derived class Ctoolboxpropbar using the methods described earlier. When creating this derived class, if you choose the MFC type, you cannot directly select the base class as Cbasetoolbar, you can select CToolBar and then manually modify it. You can also directly select the C + + type, do not select MFC, so that we can specify any class name.

Adding four member variables to the header file of the Ctoolboxpropbar class represents four controls. The methods introduced in some books and articles are to add control variables to CMainFrame, and then create them in the CMainFrame::OnCreate () function, which, while feasible, can cause CMainFrame to be too large and bloated in actual projects. , not convenient management. So we've separated the creation process of these controls through classes such as Ctoolboxpropbar. Then add a child control to the Ctoolboxpropbar class to create the function void Createsubcontrol (), and the header file for the toolbar after adding:

Class Ctoolboxpropbar
{
.../omitting part of the code, ....//omitted
CStatic m_static;
CStatic M_static2;
CComboBox M_brushstyle;
CComboBox m_brushsize;
void Createsubcontrol ();
};

You might want to put the code that creates the control into the OnCreate function of the Ctoolboxpropbar class. No way! Because we need to access the Ctoolboxpropbar object when we create the control, if we access it directly in the OnCreate function, it means that the control has not been created successfully and the access will fail. So we need a separate executive function. And calling this function must be successful after the Ctoolboxpropbar creation.

void Ctoolboxpropbar:: Createsubcontrol ()
{
Hgdiobj Hfont = Getstockobject (Default_gui_font); Take the default GUI font
CFont font;
Font. Attach (Hfont);
Set the Idc_1 (ID of the number 1 button in Figure 2-1) to a separator bar
int nindex = GetToolBarCtrl (). Commandtoindex (idc_1);
SetButtonInfo (nindex, Idc_1, Tbbs_separator, 60); 60 indicates the width of the control
RECT RECT;
GetItemRect (nindex, &rect);
M_static.create (_t ("Fill style:"), ws_child| Ws_visible, rect, this, idc_static);
M_static.setfont (&font);

nindex = GetToolBarCtrl (). Commandtoindex (idc_2);
SetButtonInfo (nindex, idc_2, Tbbs_separator, 100);
GetItemRect (nindex, &rect);
M_brushstyle.create ("", ws_child| Ws_visible, rect, this, Id_combobox_styel);

nindex = GetToolBarCtrl (). Commandtoindex (IDC_3);
SetButtonInfo (nindex, Idc_3, Tbbs_separator, 60);
GetItemRect (nindex, &rect);
M_static2.create (_t ("Picture brush Size:"), ws_child| ws_visible|, rect, this, idc_3);
M_static2.setfont (&font);

nindex = GetToolBarCtrl (). Commandtoindex (Idc_4);
SetButtonInfo (nindex, Idc_4, Tbbs_separator, 50);
GetItemRect (nindex, &rect);
M_brushsize.create ("", ws_child| Ws_visible, rect, this, id_combobox_width);
M_brushsize.setfont (&font);
}

The final call procedure is very simple, like creating a normal toolbar in the CMainFrame class, creating the Ctoolboxpropbar toolbar in the OnCreate function, simply calling Createsubcontrol after the toolbar create.
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.