词条 | GetDlgItemInt |
释义 | GetDlgItemInt获取控件中里面字符串并转换成int类型返回. UINT GetDlgItemInt( HWNDhDlg, // 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); |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。