1.1.7-learning opencv and MFC mixed programming-Add a toolbar for the drawing tool

Source: Internet
Author: User

Source code: http://download.csdn.net/detail/nuptboyzhb/3961701

Ah, actually there are a lot of pictures in it. It was very clear that there are detailed documents in the resource connection, which is much more comfortable than the following ....

Add toolbar for drawing tool

First, let's take a look at the operations on the toolbar.

1. Open the resource-> Toolbar

2. How to view the attributes of each icon?

You can view the attributes of each icon, instead of right-clicking the icon, and double-clicking the image with the left-click button, as shown in the following figure:

Double-click to open the icon. the following property box is displayed:

The resource ID of the 'open 'icon is id_file_new. This ID exactly corresponds to the resource ID of the 'file'-> 'open' menu item in the menu item.

Therefore, when we press the 'open' icon in the toolbar, we can perform the same functions as by menu item.

3. How do I add a separator between icons on the toolbar?

You only need to drag it with the mouse. Drag an icon to a farther place.

4. How do I delete an icon?

Drag the mouse and drag it out of the toolbar.

Add a toolbar for the project drawing tool.

1. Edit toolbar resources, draw an icon for each tool, double-click the icon, and set the icon attributes so that the resource ID corresponds to the resource ID of each tool menu in the menu item. Edit and run.

2. It's over!

Create your own Toolbar

1. Insert, resource, select toolbar, and click Create. Set the resource button to idr_my_toolbar.

2. Edit several ICON resources, such:

And set the corresponding properties. Set the resource ID to the same as the resource ID of the menu item of the drawing tool.

3. Add the member variable ctoolbar m_mytoolbar to the cmainframe class, and add the following code in the oncreate (lpcreatestruct) function of the cmainframe class:

If (! M_mytoolbar.createex (this, tbstyle_flat, ws_child | ws_visible | cbrs_left

| Cbrs_gripper | cbrs_tooltips | cbrs_flyby | cbrs_size_dynamic) |

! M_mytoolbar.loadtoolbar (idr_my_toolbar ))

{

Trace0 ("failedto create Toolbar \ n ");

Return-1; // fail to create

}

M_mytoolbar.enabledocking (cbrs_align_any );

Enabledocking (cbrs_align_any );

Dockcontrolbar (& m_mytoolbar );

4. Edit and run the task.

A running error occurs when the member variable ctoolbar m_mytoolbar is added. The error message is that some memory unreadable errors occur. Delete all files under the release file.

Ø complete functions: Add menu items for display on the toolbar;

1. Add the 'view' menu item and set it to the pop-up type.

2. Under the 'view' menu item, add the 'System toolbar 'and 'Drawing toolbar' menu items. Set the corresponding properties and create the Class Wizard respectively. (Note): when creating the Class Wizard, select add to the cmainframe class. Add the following commands to the corresponding function of the message:

Void cmainframe: onviewsystembar ()

{

// Todo: add your command handler code here

Showcontrolbar (& m_wndtoolbar ,! M_wndtoolbar.iswindowvisible (), false );

}

 

Void cmainframe: onviewdrawbar ()

{

// Todo: add your command handler code here

Showcontrolbar (& m_mytoolbar ,! M_mytoolbar.iswindowvisible (), false );

}

3. The menu item function is basically completed. Next we add the 'check' mark for the menu item selection.

Add the updata_command_ui message processing function for the menu items 'System toolbar 'and 'Drawing toolbar. Right-click and choose create Class Wizard,

Select updata_command_ui. Select cmainframe for the class name. Add a function and edit the Code:

Voidcmainframe: onupdateviewsystembar (ccmdui * pcmdui)

{

// Todo: add your command update UI handler code here

Pcmdui-> setcheck (m_wndtoolbar.iswindowvisible ());

}

 

Void cmainframe: onupdateviewdrawbar (ccmdui * pcmdui)

{

// Todo: add your command update UI handler code here

Pcmdui-> setcheck (m_mytoolbar.iswindowvisible ());

}

Add a check prompt for each menu item of the drawing tool;

Right-click respectively, create Class Wizard, select updata_command_ui. Select cxxxxview for class name. Add function and edit code:

Void ccvmfcview: onupdatemydrawline (ccmdui * pcmdui)

{

// Todo: add your command update UI handler code here

Pcmdui-> setcheck (my_draw_flag = 1 );

}

 

Voidccvmfcview: onupdatemydrawrectangle (ccmdui * pcmdui)

{

// Todo: add your command update UI handler code here

Pcmdui-> setcheck (my_draw_flag = 2 );

}

 

Void ccvmfcview: onupdatemydrawcircle (ccmdui * pcmdui)

{

// Todo: add your command update UI handler code here

Pcmdui-> setcheck (my_draw_flag = 3 );

}

 

Voidccvmfcview: onupdatemydrawconceal (ccmdui * pcmdui)

{

// Todo: add your command update UI handler code here

Pcmdui-> setcheck (my_draw_flag = 0 );

}

 

Void ccvmfcview: onupdatemydrawcurve (ccmdui * pcmdui)

{

// Todo: add your command update UI handler code here

Pcmdui-> setcheck (my_draw_flag = 4 );

}

 

Voidccvmfcview: onupdatemydrawellipse (ccmdui * pcmdui)

{

// Todo: add your command update UI handler code here

Pcmdui-> setcheck (my_draw_flag = 5 );

}

 

Void ccvmfcview: onupdatemydrawtext (ccmdui * pcmdui)

{

// Todo: add your command update UI handler code here

Pcmdui-> setcheck (my_draw_flag = 6 );

}

Add the {prompt} function for each tool menu. That is, when you move the mouse over a menu item, the function of this menu item is displayed in the lower left corner of the program.

Method 1: Set the properties of the menu item. In the last column of the property, enter the corresponding prompt in the prompt bar.

Method 2: Open the resource file XXXX. RC and use NotePad to open it;

Add the following code:

Add the menu item ID and the corresponding string between begin and end:

For example:

Stringtable discardable

Begin

Id_my_draw_line "draw a straight line (drag the mouse )"

Id_my_draw_conceal "cancel tool"

Id_my_draw_rectangle "draw a rectangle (drag the mouse )"

Id_my_draw_circle "Circle (drag the mouse )"

Id_my_draw_ellipse "draw an ellipse (drag the mouse )"

Id_my_draw_text "write text (drag the mouse )"

Id_my_draw_curve "draw any curve (drag the mouse )"

End

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.