GetDlgItemInt

to in tn

GetDlgItemInt

獲取控制項中裡面字元串並轉換成int類型返回.
UINT GetDlgItemInt(
HWND
hDlg, // handle to dialog box
intnIDDlgItem, // control identifier
BOOL*lpTranslated, // success state
BOOLbSigned // signed or unsigned value
);
Parameters hDlg [in] Handle to the dialog box that contains the control of interest. nIDDlgItem [in] Specifies the identifier of the control whose text is to be translated. lpTranslated [out] Pointer to a variable that receives a success or failure value (TRUE indicates success, FALSE indicates failure). If this parameter is NULL, the function returns no information about success or failure. bSigned [in] Specifies whether the function should examine the text for a minus sign at the beginning and return a signed integer value if it finds one (TRUE specifies this should be done, FALSE that it should not). Return ValuesIf the function succeeds, the variable pointed to by lpTranslated is set to TRUE, and the return value is the translated value of the control text.
If the function fails, the variable pointed to by lpTranslated is set to FALSE, and the return value is zero. Note that, since zero is a possible translated value, a return value of zero does not by itself indicate failure.
If lpTranslated is NULL, the function returns no information about success or failure.
If the bSigned parameter is TRUE, specifying that the value to be retrieved is a signed integer value, cast the return value to an int type. To get extended error information, call GetLastError.
RemarksThe GetDlgItemInt function retrieves the text of the specified control by sending the control a WM_GETTEXT message. The function translates the retrieved text by stripping any extra spaces at the beginning of the text and then converting the decimal digits. The function stops translating when it reaches the end of the text or encounters a nonnumeric character.
If the bSigned parameter is TRUE, the GetDlgItemInt function checks for a minus sign (–) at the beginning of the text and translates the text into a signed integer value. otherwise, the function creates an unsigned integer value.
The GetDlgItemInt function returns zero if the translated value is greater than INT_MAX (for signed numbers) or UINT_MAX (for unsigned numbers).
Example CodeFor an example, see Creating a Modeless Dialog Box.
Requirements Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Winuser.h; include Windows.h.
Library: Use User32.lib.
使用例子如下:
這裡的第二個參數,主要是為了接收錯誤信息的 可能出現的錯誤信息有: ID無效,並且超過指定大小,比如說:ID為12345677,這個就不行. 還有就是輸入不能解析為一個int類型的,比如輸入:"bvbvbvbv","3.5666", 當然後面可以解析為一個浮點型,在這裡取得的值為3,但是還是會有錯誤信息如果不指定第二個參數,就不會獲得任何錯誤信息,這個參數很有用的,對輸入的判斷是否可以解析為int類型或者是否有效,很有用的,我們經常有這個參數來判斷用戶的輸入是否合法 參數3:默認的為true,主要是針對"-123",像這樣的字元,它可以把前面的"-"解析為負號,那么就是標準的int類型了,如果設定為false,那么它不可以有負數,因為在這裡的"-"號,被認為是不合法的
用途如下:
BOOL flag;
UINT ui=GetDlgItemInt(IDC_EDIT1,&flag,true);
CString cs;
cs.Format("%d,%d",ui,flag);
MessageBox(cs);

相關詞條

相關搜尋

熱門詞條

聯絡我們