BOOL GetCharWidth(hdc, uFirstChar, uLastChar, lpnWidths) | |||||
HDC hdc; | /* handle of device context | */ | |||
UINT uFirstChar; | /* first character in range to query | */ | |||
UINT uLastChar; | /* last character in range to query | */ | |||
int FAR* lpnWidths; | /* address of buffer for widths | */ |
The GetCharWidth function retrieves the widths of individual characters in a range of consecutive characters in the current font.
hdc
Identifies the device context.
uFirstChar
Specifies the first character in a group of consecutive characters in the current font.
uLastChar
Specifies the last character in a group of consecutive characters in the current font.
lpnWidths
Points to a buffer that receives the width values for a group of consecutive characters in the current font.
The return value is nonzero if the function is successful. Otherwise, it is zero.
If a character in the group of consecutive characters does not exist in a particular font, it will be assigned the width value of the default character.
The following example uses the GetCharWidth function to retrieve the widths of the characters from “I” through “S” and displays the total number of widths retrieved in a message box:
HDC hdc;
WORD wTotalValues;
WORD wFirstChar, wLastChar;
int InfoBuffer[256];
char szMessage[30];
wFirstChar = (WORD) 'I';
wLastChar = (WORD) 'S';
hdc = GetDC(hwnd);
if (GetCharWidth(hdc, wFirstChar, wLastChar, (int FAR*) InfoBuffer)) {
wTotalValues = wLastChar - wFirstChar + 1;
wsprintf(szMessage, "Total values received: %d", wTotalValues);
MessageBox(hwnd, szMessage, "GetCharWidth", MB_OK);
}
else
MessageBox(hwnd, "GetCharWidth was unsuccessful", "ERROR!",
MB_OK);
ReleaseDC(hwnd, hdc);