Welcome: Hunan Intelligent Applications Tecgnology CO.,ltd.-HNIAT.com
Language: Chinese ∷  English

Basic knowledge

Summary of MFC common functions

1. Common functions related to MFC edit box and static text box

"1" GetDlgItemText (ID, str)

Purpose: Get text from dialog

The first parameter is the ID of the edit box (or a static text box, radio button, and other controls that can display content) to be obtained, and the second parameter is a string (Cstring type) variable. The obtained text is stored in str .

《2》 SetDlgItemText (ID, str)

Role: Display the string in the control

The first parameter is the ID of the edit box (or a static text box, radio button, combo box, and other controls that can display content) to be displayed. The second parameter is a string (Cstring type) variable. The displayed text is stored. In str. If the type of the variable to be displayed is not Cstring, it is coerced by the Format function.

Usually also add an UpDateData (FALSE).

《3》 UINT nID = GetCheckedRadioButton (IDC1, IDC2);

Role: Get the ID of the radio button option

The first parameter is the ID of the first radio button in the combo box, and the second parameter is the ID of the last button in the combo box.

《4》 CheckRadioButton (IDC1, IDC2, IDC3);

Role: Initialize radio buttons

The first parameter is the ID of the first radio button in the combo box, the second parameter is the ID of the last button in the combo box, and the third parameter is the ID of the default option.

"5" m_scrollBar.SetScrollRange (0, 500);

Function: Set the value range of the horizontal scroll bar, m_scrollBar is the variable of the control type of the horizontal scroll bar, 0 is the set minimum value, and 500 is the set maximum value.

《6》 m_nAmount = m_slider.GetPos ();

Role: Get the current position of the slider.

"7" m_slider.SetRange (0,1000);

Function: // Set the slider value range

The first parameter is the set minimum value, and the second parameter is the set maximum value.

《8》 double Volum = atof (strCtrl);

Role: Convert the string strCtl to a floating-point Volum

"9" int Volum = atof (strCtrl);

Role: convert string strCtl to integer Volum

"10" MessageBox (str); (local function)

Role: output string str

"11" AfxMessageBox (str); (Global function)

Role: output string str

"12" tempt = m_time2.Format ("% H:% m:% S");

Role: convert time to character (hour, minute, second)

m_time2 is a variable of the calendar time picker, and tempt is a CString variable

"13" tempt = m_time.Format ("% Y-% m-% d"); // Convert time to character

Role: convert time to character (year, month, day)

m_time2 is a variable of the calendar time picker, and tempt is a CString variable

《14》 m_time = CTime :: GetCurrentTime ();

Role: Get the system's current time

m_time is a variable of type Ctime.

"15" m_list.AddString (str);

Function: Display the contents of Cstrig type variables in the list box (or combo box).

m_str is a variable of type ClistBox (or a variable of type CcomboBox).

"16" m_time = CTime (2012,5,28,0,0,0);

Function: Initialization date

m_time is a variable of type Ctime

"17" str.TrimLeft ();

Function: remove the left space of Cstring type variables

"18" str.TrimRight ();

Function: remove the space on the right side of Cstring type variables

"19" str.IsEmpty ();

Function: Determine whether the variable str of type Cstring is empty. If it is empty, it returns 1;

《20》 int nIndex = m_list.FindString (int k, str);

Function: Find list items that match str in the list box, m_list is a ClistBox type variable.

Search from the kth position, if -1, search from beginning to end.

Function prototype:

int FindString (int nStartAfter, LPCTSTR lpszItem) const;

int FindStringExact (int nIndexStart, LPCTSTR lpszFind) const;

Among them, FindStringExact has the highest search accuracy

"21" m_list.ResetContent ();

Function: Clear the contents of the list box

m_list is a ClistBox type variable.

"22" m_listSearch.DeleteString (int nIndex);

Function: Delete the nIndex record in the list box.

m_listSearch is a ClistBox type variable.

《23》 GetDlgItem (IDC_BUTTON_DELETE)-> EnableWindow (FALSE);

Function: It is the gray selection of the button whose ID is IDC_BUTTON_DELETE.

《24》 GetDlgItem (IDC_BUTTON_DELETE)-> EnableWindow (TRUE);

Function: It is a button with ID IDC_BUTTON_DELETE.

"25" str.Left (length);

Function: Get the length of the string str to the left.

《26》 int length = str.GetLength ();

Function: Get the length of the string str

"27" dlg.DoModal ();

Function: Create a dialog box

dlg is an object of the class of this dialog.

《28》 CDialog :: OnCancel ();

Function: Close window

《29》 CMenu * pSysMenu = GetMenu ();

Function: Get program menu pointer

《30》 int nCount = pSysMenu-> GetMenuItemCount ();

Function: Get the number of items in the item-level menu item

《31》 int nIndex = m_ListBox.GetCurSel ();

Function: Get the position of the pointer in the list box

m_ListBox is a ClistBox type variable.

"32" GetWindowText (str);

Function: Get the title of the current window

Str is a Cstring variable

 

《33》 GetDlgItem (IDC_CLICKHERE)-> SetFocus ();

Set the cursor at the control IDC_CLICKHERE. If you do this when you open a dialog box, add the statement before the return statement of the message processing function OnInitDialog and return the final statement to TRUE; the return FALSE;

GetDlgItem (IDC_CLICKHERE)-> SetFocus (); can also be written as m_strit.SetFocus ();

Where m_strit is the variable corresponding to the control.

 

"34" GetDlgItem (IDC_STATIC_NUMBER1)

Function: Get the pointer of ID IDC_STATIC_NUMBER1 control.

E.g:

CString str;

GetDlgItem (IDC_STATIC_NUMBER1)-> GetWindowText (str); // This sentence is equivalent to

GetDlgItemText (IDC_STATIC_NUMBER1, str);

 

《35》 int num1 = GetDlgItemInt (IDC_EDIT1);

Function: Get the text whose ID is IDC_EDIT1 control and convert it to an integer value. If the text contains non-numeric characters, the conversion fails.

 

《36》 SetDlgItemInt (IDC_EDIT3, num3);

Function: Display the integer num3 in the edit box with ID IDC_EDIT3.

 

《37》 :: SendMessage (GetDlgItem (IDC_EDIT1)-> m_hWnd, WM_GETTEXT, 10, (LPARAM) ch1);

Note: Adding a scope section before the function means that the global function is called.

Function: Take the text of ID IDC_EDIT1 control, get the maximum length of 10, and store the obtained content in ch1. Equivalent to GetDlgItemText (IDC_EDIT1, ch1,10);

Note: The first parameter is the handle of the corresponding control, the second parameter is the message name, the third parameter is the maximum length of the obtained text, and the fourth parameter is the buffer to store the text, where ch1 is the character array, that is, char ch1 [10]; the type of the fourth parameter must be cast to LPARAM.

There are multiple ways to call this function, and their functions are the same. Listed as follows:

(1) :: SendMessage (GetDlgItem (IDC_EDIT1)-> m_hWnd, WM_GETTEXT, 10, (LPARAM) ch1);

(2) GetDlgItem (IDC_EDIT1)-> SendMessage (WM_GETTEXT, 10, (LPARAM) ch1);

(3) m_edit1.SendMessage (WM_GETTEXT, 10, (LPARAM) ch1);

(4) :: SendMessage (m_edit1.m_hWnd, WM_GETTEXT, 10, (LPARAM) ch1);

Where m_edit1 is a variable of IDC_EDIT1 control type Control and type CEdit.

 

《38》 :: SendMessage (GetDlgItem (IDC_EDIT3)-> m_hWnd, WM_SETTEXT, 0, (LPARAM) ch3);

Function: Display the content of buffer ch3 on D as IDC_EDIT1 control. Its function is equivalent to SetDlgItemText (IDC_EDIT1, ch1);

Note: the first parameter is the handle of the corresponding control, the second parameter is the message name, the third parameter is not used, so it is set to zero, the fourth parameter is the text content to be displayed, and the type of the fourth parameter Must be coerced to LPARAM.

 

《39》 SendDlgItemMessage (IDC_EDIT1, WM_GETTEXT, 10, (LPARAM) ch1);

The function is equivalent to :: SendMessage (GetDlgItem (IDC_EDIT1)-> m_hWnd, WM_GETTEXT, 10, (LPARAM) ch1);

 

《40》 SendDlgItemMessage (IDC_EDIT3, WM_SETTEXT, 0, (LPARAM) ch3);

The function is equivalent to :: SendMessage (GetDlgItem (IDC_EDIT3)-> m_hWnd, WM_SETTEXT, 0, (LPARAM) ch3);

2, commonly used functions (compared to all)

WinExec ()

ExitWindowsEx ()

GlobalMemoryStatus ()

GetSystemInfo ()

GetSystemDirectory ()

GetWindowsDirectory ()

GetTaskmanWindow () //user32.dll Get taskbar window handle

 

OpenProcessToken () opens the access token of a process

GetCurrentProcess ()

LookupPrivilegeValue () modify process permissions

AdjustTokenProvileges () notifies WindowsNT to modify the rights of this process

 

CreateRectRgn ()

CreateEllipticRgnIndirect ()

PtInRegion ()

CommandToIndex () ID number is converted into an index value

 

Menu:

DrawMenuBar () to redraw the menu

SetDefaultItem () sets the default menu item

CheckMenuItem () sets the check state of the menu item

CreatePopupMenu ()

 

Window class:

MoveWindow ()

Invalidate () invalidates the window, and redraws the window when it is invalid

GetParent () get the parent window handle of the window

BringWindow


Please read the Chinese version for the details.

CONTACT US

Contact: Manager Xu

Phone: 13907330718

Tel: 0731-22222718

Email: hniatcom@163.com

Add: Room 603, 6th Floor, Shifting Room, No. 2, Orbit Zhigu, No. 79 Liancheng Road, Shifeng District, Zhuzhou City, Hunan Province

Scan the qr codeClose
the qr code