Source code: http://download.csdn.net/detail/nuptboyzhb/3961696
Input text
LDialog Box
1. Insert, resource, select Resources in the dialog box
2. the edit dialog box is as follows:
Set the properties of each control.
3. Double-click the dialog box to create a class in the dialog box named textsetdlg.
4. Add public member variables to the dialog box class as follows:
Int m_colorr;
Int m_colorg;
Int m_colorb;
Double dlg_hscale;
Double dlg_vscale;
Double dlg_shear;
Int dlg_thick;
Cstring str_text;
5. initialize the member variables in the constructor in the dialog box.
6. Write the input value on the control to the member variable in the data exchange function. Check whether the entered number is valid.
Voidtextsetdlg: dodataexchange (cdataexchange * PDX)
{
Cdialog: dodataexchange (PDX );
// {Afx_data_map (textsetdlg)
Ddx_text (PDX, idc_color_r, m_colorr );
Ddv_minmaxint (PDX, m_colorr, 0,255 );
Ddx_text (PDX, idc_color_g, m_colorg );
Ddv_minmaxint (pdx, m_colorg, 0,255 );
Ddx_text (PDX, idc_color_ B, m_colorb );
Ddv_minmaxint (PDX, m_colorb, 0,255 );
//----------------------------------
Ddx_text (PDX, idc_font_width, dlg_hscale );
Ddv_minmaxdouble (PDX, dlg_hscale, 0.1, 5 );
Ddx_text (PDX, idc_font_hight, dlg_vscale );
Ddv_minmaxdouble (PDX, dlg_vscaling, 0.1, 5 );
Ddx_text (PDX, idc_font_shear, dlg_shear );
Ddv_minmaxdouble (PDX, dlg_shear, 0, 1.5 );
Ddx_text (PDX, idc_font_thick, dlg_thick );
Ddv_minmaxint (PDX, dlg_thick, 1, 20 );
//--------------------------------------
Ddx_text (PDX, idc_text, str_text );
// Note: The classwizard will add DDX and DDV cballs here
//} Afx_data_map
}
7. Click OK to add a message response function. Edit as follows:
Void textsetdlg: onok ()
{
// Todo: add extra validation here
Updatedata (true );// Write data on the control to the member variable
Cdialog: onok ();
}
LUse of the dialog box
1.Add'Text' menu item, and add the corresponding message processing function. In the message processing function, set the drawing flag;
My_draw_flag = 6;
2. Edit the onmousemove message processing function.
2.1. Add variable
Textsetdlgdlg;
Cvfont font;
Double hscale;
Double vscale;
Double Shear = 0;
Int fontthickness = 1;
Cstringtext;
2.2. compile case 6: The program is as follows:
If (DLG. domodal ()! = Idok)
{
Onlbuttonuprunflag = 1;
Return;
}
// Pass the following parameters
Hscale = DLG. dlg_vscale;
Vscale = DLG. dlg_vscale;
Shear = DLG. dlg_shear;
Fontthickness = DLG. dlg_thick;
TEXT = DLG. str_text;
Colorb = DLG. m_colorb;
Colorg = DLG. m_colorg;
Colorr = DLG. m_colorr;
Deletedlg; // deletion dialog box
Cvinitfont (& font, cv_font_hershey_simplex, hscale, vscale,
Shear, fontthickness );
Cvflip (SRC );
Cvputtext (SRC, text, iner_point, & font, cvscalar (colorb, colorg, colorr ));
Cvflip (SRC );
Onlbuttonuprunflag = 1;
Workimg = cvcloneimage (SRC); // copy to work zone
Invalidate (); // redraw
Break;
ØAddition: Fill images can be drawn when circles, rectangles, and rectangles are drawn.
1.In the lineparameter dialog box, add a single choice button.
Set the corresponding attributes.
2.Add the onmydrawfull function to the single-choice button.
3.Added the bool member variable "full" and initialized to "false" in the constructor.
4.Set full to true in the single-choice button event processing function.
ØModify menu items in cxxxxview.
1.Add the bool type member variable m_fullornot to the cxxxxview class and initialize it to false in the constructor.
2. on the message processing function of a rectangle, an oval, or single dish, add the dialog box transfer statement: m_fullornot = DLG. Full;
3. In the onmousemove message processing function, modify the thickness value assignment statement:
If (m_fullornot = true)
{
Thickness =-1; // fill
}
Else
{
Thickness = m_linewidth;
}
Modify the mouse drawing in real time.
1. Insert, resource, select cursor resource, and create
2. The resource diagram is as follows:
3. Use the drawing tool on the right to draw the following Cursor Image
4. Add the following statement to the onmousemove function of the cxxxxview class:
Setcursor (afxgetapp ()-> loadcursor (idc_cursor1); // load the cursor Resource
Note the position to add