Basic knowledge of MFC

Source: Internet
Author: User

Ccombox ::

Set a pointer to idc_combo1 and fill the drop-down box with addstring:

Ccombobox * pcomb = NULL;
Pcomb = (ccombobox *) This-> getdlgitem (idc_combo1 );
Pcomb-> addstring ("COM1 ");
Pcomb-> addstring ("com2 ");
Pcomb-> addstring ("com3 ");

Obtain the index in the drop-down box and assign its value to a variable:


Index = pcomb-> getcursel ();
Pcomb-> getlbtext (index, value );

Set the value of the text box:


Cstring strtemp;
Getdlgitemtext (idc_combo, strtemp );
Strtemp + = "";
Setdlgitemtext (idc_combo, strtemp );

Status Bar ):

In the status bar, add a window (id_statusbar_str) with the value of "test". First, find the struct of indicators in mainfrm, and then

Add "id_statusbar_str" to the struct as follows:


Static uint indicators [] =
Id_separator, // status line indicator
Id_indicator_scrl, id_statusbar_str,

Of course, you can also add the status bar form (id_statusbar_str) to "resource symbols" in "View" A menu. The following code can be used:

Dynamically change the value of the status bar window (id_statusbar_str) in the program:


Cclientdc DC (this );
Size size = Dc, gettextextent ("test successfully pulled! ");
Int Index = m_wndstatusbar.commandtoindex (id_status );
M_wndstatusbar.setpanelinfo (index, id_status_str, sbps_popout, size. CX );
M_wndstatusbar.setpaneltext (index, _ T ("test pulled successfully! ", True );

Image processing:


DC means the device environment. The full name of GDI is graphics device interface, which is the graphical device interface.

DC is used to complete the drawing, and GDI is used to complete the drawing. Therefore, DC should be initialized before the Drawing Object is initialized.


Base Class Cobject      
DC type CDC      
Derived class Cpaintdc Cclientdc Cwindowsdc Cmetafiledc

Differences between cwindowsdc and cpaintdc and cclientdc:

1. The cwindows class can plot in the customer and non-customer areas, while cpaintdc and cclientdc can only plot in the customer area, so cwindows

To be used in the mainfrm class, use in the veiwl class cannot be used in non-customer areas;

2. The cwindows class creates coordinates throughout the screen, while the cpointdc and cclientdc create coordinates in the customer zone.

Drawing equipment (GDI ):

Base Class Cgdiobject          
Derived class Cpen Cbrush Cfont Cbitmap Crgn Cpalette

Steps for using the drawing class:

1. Define a GDI object (such as cpen and cbrush), and then call the corresponding functions (such as createpen and creatsolidbrush) to create this GDI


2. Select the constructed GDI object from the member function selectobjiect () of the device environment class to the current environment, and

Save the image;

3. After the drawing is complete, restore the original GDI object in the current device environment, that is, use the selectobjict member function of the device environment class


The following is an example of a cpen plot:

Cpen pen;

Pen. creatpen (OS _solid, 1, RGB (255, 0, 0 ));

Cpen * poldpen = PDC-> selectobjiect (& pen );


PDC-> selectobjiect (poldpen );

Change the font size of the Edit Control:

Cclientdc DC (this );
Cedit * pedit = (cedit *) getdlgitem (idc_edit1 );
Cfont * font = new cfont;
Font-> createpointfont (400, _ T (" 文 "), & DC );
If (pedit)
Pedit-> setfont (font, true );
Afxmessagebox ("failed ");


Obtain the Application Path:


Lptstr lppath = new char [max_path];
Getcurrentdirectory (max_path, lppath );
Strpath = lppath;
Strpath + = "//";
Strpath + = "test. ini ";


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: 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.