UINT GetDlgItemInt(hwndDlg, idControl, lpfTranslated, fSigned) | |||||
HWND hwndDlg; | /* handle of dialog box | */ | |||
int idControl; | /* identifier of control | */ | |||
BOOL *lpfTranslated; | /* address of variable for error flag | */ | |||
BOOL fSigned; | /* signed or unsigned indicator | */ |
The GetDlgItemInt function translates the text of a control in the given dialog box into an integer value.
hwndDlg
Identifies the dialog box.
idControl
Specifies the integer identifier of the dialog-box item to be translated.
lpfTranslated
Points to the Boolean variable that is to receive the translated flag.
fSigned
Specifies whether the value to be retrieved is signed.
The return value specifies the translated value of the dialog box item text if the function is successful. Because zero is a valid return value, the lpfTranslated parameter must be used to detect errors. If an application requires a signed return value, it should cast the return value as an int type.
The function retrieves the text of the given control by sending the control a WM_GETTEXT message. The function then translates the text by stripping any extra spaces at the beginning of the text and converting decimal digits. The function stops translating when it reaches the end of the text or encounters a nonnumeric character. If the fSigned parameter is TRUE, the GetDlgItemInt function checks for a minus sign (–) at the beginning of the text and translates the text into a signed number. Otherwise, it creates an unsigned value.
GetDlgItemInt returns zero if the translated number is greater than INT_MAX (for signed numbers) or UINT_MAX (for WORD). When errors occur, such as encountering nonnumeric characters and exceeding the given maximum, GetDlgItemInt copies zero to the location pointed to by the lpfTranslated parameter. If there are no errors, lpfTranslated receives a nonzero value. If lpfTranslated is NULL, GetDlgItemInt does not warn about errors. GetDlgItemInt sends a WM_GETTEXT message to the control.
GetDlgCtrlID, GetDlgItem, GetDlgItemText, SetDlgItemInt