GetDlgItemInt

2.x

  UINT GetDlgItemInt(hwndDlg, idControl, lpfTranslated, fSigned)    
  HWND hwndDlg; /* handle of dialog box */
  int idControl; /* identifier of control */
  BOOL FAR* 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.

Parameters

hwndDlg

Identifies the dialog box.

idControl

Specifies the identifier of the dialog box control 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.

Return Value

The return value specifies the translated value of the dialog box item text if the function is successful. Since 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.

Comments

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 32,767 (for signed numbers) or 65,535 (for unsigned numbers). When a error occurs, 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.

See Also

GetDlgCtrlID, GetDlgItem, GetDlgItemText