Adding Point Sizes to the ChooseFont() Common Dialog BoxLast reviewed: November 2, 1995Article ID: Q99668 |
The information in this article applies to:
SUMMARYWhen a TrueType font (or any other scalable font) is selected in the ChooseFont() common dialog box, a list of reasonable point sizes is displayed for selection. In some cases it is necessary to change this list to allow fewer or more selections. The initial list of point sizes is hard-coded into COMMDLG.DLL but can be changed programmatically using a common dialog box hook function.
MORE INFORMATIONMost scalable fonts can be created at nearly any point size. Some TrueType fonts can be sized from 4 points to 999 points. A complete list of available point sizes for a font of this type would contain about 1000 elements, which can be prohibitively long and time-consuming to construct. The ChooseFont() common dialog box attempts to limit the selection by listing only a few of the available point sizes in the size selection combo box. In certain cases, it may be desirable to offer more point-size selections in this dialog box. In this case, a common dialog box hook procedure can be used to insert point sizes when a specific font is selected. The following steps describe a technique that will allow new point sizes to be added to the size selection combo box. Pay special attention to step number 4:
// Common Dialog ChooseFont() hook procedure.UINT CALLBACK __export FontHook(HWND hwnd, UINT wm, WPARAM wParam, LPARAM lParam) { char szBuf[150]; DWORD dwIndex; switch(wm) { case WM_COMMAND: // See if the notification is for the "Font name" combo box. if (wParam == cmb1) { switch (HIWORD(lParam)) { case CBN_SETFOCUS: case CBN_KILLFOCUS: break; default: // Check to see if it's the font we're looking for. dwIndex = SendDlgItemMessage(hwnd, cmb1, CB_GETCURSEL, 0, 0); if (dwIndex != CB_ERR) SendDlgItemMessage(hwnd, cmb1, CB_GETLBTEXT, (WPARAM) dwIndex, (LPARAM) ((LPSTR) szBuf)); // Compare list box contents to the font we are looking for. // In this case, it's "Courier New". if (strcmp(szBuf, "Courier New") == 0) // It's the font we want. Post ourselves a message. PostMessage(hwnd, WM_ADDNEWPOINTSIZES, 0, 0L); } } break; case WM_ADDNEWPOINTSIZES: // First look to see if we've already added point sizes to this // combo box. if (SendDlgItemMessage(hwnd, cmb3, CB_FINDSTRING, -1, (LPARAM)(LPCSTR)"6") == CB_ERR) { // Not found, add new point size. dwIndex = SendDlgItemMessage(hwnd, cmb3, CB_INSERTSTRING, 0, (LPARAM)(LPSTR)"6"); // Also set the item data equal to the point size. SendDlgItemMessage(hwnd, cmb3, CB_SETITEMDATA, (WPARAM)dwIndex, 6); } return TRUE; // Don't pass this message on. } return FALSE;}
|
Additional reference words: 3.10 3.50 3.51 4.00 95
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |