MFC Control Usage Instructions

Source: Internet
Author: User

VC + + Control Toolbox:


2 button: A command used to receive a user, which usually requires some background work after receiving a user command. button to respond to the click or double-click Action , after the button receives the mouse action, send the corresponding control notification to its parent window, the user can the control notification for the message mapping, so that the corresponding processing. In a dialog box, you can define a default button, which simply selects the "Default" option in the button's properties. If you press the ENTER key when the dialog box is active, it is equivalent to clicking the default button. MFC provides the CButton class support button controls.

     

3 check box: Used to display a possible selection, which is independent and allows the user to select or cancel the option . The check mark appears when the option is selected, and the approval tag disappears when the option is canceled. in MFC, the CButton class supports the nuclear marquee, and the user can set or get the current state of the checkbox through the SetCheck () function and the Getcheck () function .

bst_unchecked== ((cbutton*) GetDlgItem (idc_check_res1))->getcheck ()
((cbutton*) GetDlgItem (idc_check_res1))->setcheck (true);		


4 EditControl: A string that is used to receive user input . by selecting the options for the edit box, The edit box can receive strings, numbers, passwords, and so on ; the edit box can also be set to receive patterns for multiple lines of string, which can be automatically case converted. The edit box may send a variety of control notifications to its parent window , which can be processed if the user wants to. MFC provides the CEdit class support for edit box controls .

GetDlgItem (idc_***)->setwindowtext (Cstring);
GetDlgItem (idc_***)->getwindowtext (Cstring);

5 combo Box: A combination of list boxes and edit boxes that allows users to enter new selections in addition to the choices that already exist in the list Combo. MFC provides the CComboBox class to support the combo box control.

CComboBox * AAA = (ccombobox*) (GetDlgItem (idc_***));
Aaa->addstring (_t ("* * *"));
Aaa->selectstring (0, _t ("* * *"));
Aaa->setcursel (0);

int nsel = Aaa->getcursel ();
Aaa->getlbtext (Nsel, Cstring);
if (strtype.trim () = = _t ("* *"))

6 list box: Used to Select a range of possible choices that the user can use to navigate through the scroll bar. In a list box, you can make either a single selection or multiple selections , depending on the user's settings in the Control Properties dialog box. MFC provides the CListBox class to support a list box control.


7 Frame (group box): A group of controls that surround a logical relationship, with boundaries and headings around them . It should be noted that the composition box is just a visual effect of the control to "group", The real "group" work requires some additional work. just visually show a set of logical relationships without adding any code


8 radio button (Radio button): Used to Select a possible selection, unlike the check box checkbox, this option is not independent . Typically, a few radio buttons form a group , and only one button is selected for the radio button in the same group . MFC also uses the CButton class to support radio button controls , and the SetCheck () function and the Getcheck () function apply to radio buttons as well.


9 static text: Used to display a specific string at a specified location , typically used to identify the contents of another control nearby . A string displayed in a static text control does not generally change , but it must be assigned a different food ID number when needed , and set by calling the appropriate function. MFC provides a CStatic class to support static controls .


Graphics Control: Display Bitmap (Bitmap) and icons (icon, graphics and display, mainly its square area suitable for display, the same square area can also be used (static text) static text box.


11. scroll bar (Scroll bar): This includes horizontal and vertical scroll bars, which, in addition to the visual orientation, wm_hscroll messages when the horizontal scroll bar is scrolled and The vertical scroll bar sends a WM_VSCROLL message when it is scrolled . MFC provides support for CScrollBar .


Slider control: typically used to accept a series of discrete values in a program. The user can set the value range of the slider control and can add tick marks to the control to show the meaning of a particular location. MFC provides support for CSliderCtrl classes .


Spin button: includes a pair of up and down arrows, using a spinner to increase or decrease a particular value. fine-tuning buttons often require a "buddy" control , which is usually an edit box . when the up arrow of the spinner is clicked, the number in the edit box increases, and the reverse is reduced . MFC provides support for Cpinbuttonctrl classes .


progress bar (Progress control): The current progress is reflected in an operation that requires a longer period of time . As the progress of the operation progresses, the progress bar fills the progress bar with a distinctive color. The user can set the range and current position of the progress bar. MFC provides support for CProgressCtrl classes .

cprogressctrl* ProgressBar = (cprogressctrl*) GetDlgItem (idc_progress_1);
Progressbar->setrange (0, 4);
Progressbar->setpos (0);


Hotkey Control (Hot Key): The hotkey control looks like an edit box, but in a hotkey control it immediately responds to the key combination that the user just pressed , which is especially useful when setting the program's hotkey. The hotkey control only displays the key combination on "visual" , and the task of setting the hotkey also requires the user to add code completion. MFC provides support for Chotkey classes .


List control: The following illustration shows a series of strings with icons in a certain order, listing controls provide four display modes: Large icons (icon), Small icons (Small icon), lists (list), and reports ( ). Users can add new items to the list control, or they can control the display mode of the list control. MFC provides support for CListCtrl classes .


Class

CRect rect;
M_listctrl.getclientrect (&rect);  
Add full row selection and grid style for a list view Control    
M_listctrl.setextendedstyle (M_listctrl.getextendedstyle) | Lvs_ex_fullrowselect | Lvs_ex_gridlines); 

M_listctrl.insertcolumn (0, _t ("serial number"), Lvcfmt_center, 0);    
M_listctrl.insertcolumn (1, _t ("Time"), Lvcfmt_center, 1);    
M_listctrl.insertcolumn (2, _t ("type"), Lvcfmt_center, 50, 2);

Add a record

struct INFO
{
	int			id;	
	CString time		;
	CString		type;
} info;
CString ID;
int nrow=0;
Id. Format (_t ("%d"), info.id);
M_listctrl.insertitem (nrow,id);
M_listctrl.setitemtext (Nrow, 1, info.time);
M_listctrl.setitemtext (Nrow, 2, info.type);
Nrow + +;


Tree Control: The following figure, which shows the hierarchical relationships of a series of items, the Most typical example is the display of files and folders on the disk . If you have a subproject, click an item in the tree control to expand or shrink its subprojects . MFC provides support for CTreeCtrl classes .


Class

	CDialog::OnInitDialog ();
	CTreeCtrl PTree; Ptree.modifystyle (Null,tvs_hasbuttons | Tvs_haslines | 
	Tvs_linesatroot);
	Ptree.setitemheight (30);

	Ptree.setbkcolor (RGB (122,122,122));    Tv_insertstruct Tvinsert;       Create the structure tvinsert.hparent=null of the tv_insertstruct to be added;  No parent node tvinsert.hinsertafter=tvi_last; Insert into this layer last tvinsert.item.mask=tvif_image| tvif_selectedimage|					 Tvif_text;   Mask, icon, select icon, text tvinsert.item.hitem=null;//handle is empty tvinsert.item.state=0; The state tvinsert.item.statemask=0;//state is the mask tvinsert.item.cchtextmax=6;//maximum literal length tvinsert.item.iselectedimage=0;//   Select Icon Index tvinsert.item.cchildren=0;
	Only sub Nodes Htreeitem Sysset=ptree.insertitem (_t ("XName"));
	Ptree.setitemdata (sysset,1); 
	Htreeitem hchild = Ptree.insertitem (_t ("name1"), Sysset);
	Ptree.setitemdata (hchild,11); 
	Hchild = Ptree.insertitem (_t ("name2"), Sysset);
	Ptree.setitemdata (hchild,12);        
	Hchild = Ptree.insertitem (_t ("Name3"), Sysset); Ptree.expand (Sysset,tve_expand); Expand System Settings root node Htreeitem sysmaint=ptree.insErtitem (_t ("Yname"));	  
	Ptree.setitemdata (sysmaint,2);
	M_1dlg.create (Idd_dialog_1,this); M_2dlg. Create (idd_dialog_2, this);
Tree node Toggle
void Cconfigdlg::ontvnselchangedtree (NMHDR *pnmhdr, lresult *presult)
{
	Lpnmtreeview Pnmtreeview = Reinterpret_cast<lpnmtreeview> (PNMHDR);
	TODO: Add control notification handler code here
	htreeitem hselected=pnmtreeview->itemnew.hitem;
	if (hselected!=null)
	{
		ptree.selectitem (hselected);
		int ndat = Ptree.getitemdata (hselected);

		Switch (ndat)
		{case
		1:
			/*messagebox (_t ("Yname")); */
			if (m_pprewnd)
				m_pprewnd-> ShowWindow (sw_hide);

			M_1dlg.showwindow (sw_show);
			M_pprewnd = &m_1Dlg;	
			break;
		Case 3:
			/*messagebox (_t ("XName")); */
			if (m_pprewnd)
				M_pprewnd->showwindow (sw_hide);

			M_2dlg.showwindow (sw_show);
			M_pprewnd = &m_2Dlg;	
			break;
		
		Default: Break
			;
		}
	}
	*presult = 0;
}

Change position

void Cconfigdlg::onsize (UINT ntype, int cx, int cy)
{
	cdialog::onsize (ntype, CX, CY);
	TODO: Add the Message Handler code here

	CRect Rcwnd;
	GetClientRect (&rcwnd);

	CRect rcchild = Rcwnd;
	Rcchild.top = rcwnd.top+10;
	Rcchild.bottom-=10;
	Rcchild.left + = 160;
	Rcchild.right = ten;
	CRect lanerect = rcchild;

	if (:: IsWindow (M_1DLG))
		M_1dlg.movewindow (rcchild);

	if (:: IsWindow (M_2DLG))
		M_2dlg.movewindow (rcchild);


	if (:: IsWindow (Ptree.getsafehwnd ()))
	{
		Ptree.movewindow (rcwnd.left+10,rcwnd.top+30,130,350,1);
	}
}


The property sheet control Tab controls: The following figure, which contains a large number of controls that meet the needs of the user to display or obtain a large number of data classification displays, typically the Windows taskbar per program label . Each property sheet is divided into several property pages, which are distinguished by their respective labels, which can contain other controls . When you display the property sheet, you can only display the entire contents of one property page at a time, displaying the labels of other property pages, and the user opens the corresponding property page by clicking the label. MFC provides support for CTabCtrl classes .


Initializing a binding variable

        M_tab_light.deleteallitems ();
	M_lightparkingdlg.destroywindow ();
	M_lightstatusdlg.destroywindow ();
	M_tab_light.insertitem (0, _t ("0001"));         Insert the first label
	M_tab_light.insertitem (1, _t ("0002"));  Insert a second label  
 
	CRect Tabrect;   Label control the location and size of the customer area   
	m_tab_light.getclientrect (&tabrect);    Get the Label control customer Area rect   
	//adjust tabrect so that its coverage is suitable for placing the label page   
	Tabrect.left + + 2;                  
	Tabrect.right-= 1;   
	Tabrect.top + +;   
	Tabrect.bottom-= 2; 
	M_lightparkingdlg.create (idd_dialog_light_parking, &m_tab_light);    Create the first tab page  
	m_lightstatusdlg.create (idd_dialog_light_status, &m_tab_light);    Create a second tab page  
	//m_lightparkingdlg.initdata ();
	M_lightparkingdlg.setwindowpos (NULL, Tabrect.left, Tabrect.top, Tabrect.width (), Tabrect.height (), SWP_SHOWWINDOW);

Control page Toggle

 CRect Tabrect;    Label control the location and size of the customer area m_tab_light.getclientrect (&tabrect);                  
	Get the Label control customer Area RECT//adjust tabrect so that its coverage is suitable for placing the label page Tabrect.left + + 2;   
	Tabrect.right-= 1;   
	Tabrect.top + 21;
	Tabrect.bottom-= 2; Switch (M_tab_light.getcursel ()) {case 0:m_lightstatusdlg.setwindowpos (NULL, Tabrect.left, Tabrect.top, TabRect.Wi
		DTH (), Tabrect.height (), Swp_hidewindow);   
		M_lightparkingdlg.setwindowpos (NULL, Tabrect.left, Tabrect.top, Tabrect.width (), Tabrect.height (), SWP_SHOWWINDOW); break; 

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.