Microsoft KB Archive/99668

{|
 * width="100%"|

HOWTO: Add Point Sizes to the ChooseFont Common Dialog Box

 * }

Q99668

-

The information in this article applies to:


 * Microsoft Win32 Software Development Kit (SDK)
 * Microsoft Windows Software Development Kit (SDK) 3.1

-

SUMMARY
When 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 INFORMATION
Most 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:


 * 1) In your common dialog box hook procedure, look for WM_COMMAND messages with wParam equal to the font name combo box (which is &quot;cmb1&quot; for Windows version 3.1).
 * 2) When you get this message(s), check for the font name you are looking for (for example, you can compare the current selection to &quot;Courier New&quot;). If it's not the font you want, return.
 * 3) If this is the font you want, post yourself a user-defined message. In response to this message, add the new point size to the Point Size combo box (which is &quot;cmb3&quot; for Windows 3.1). It's a good idea to double-check here that the point size you are adding isn't already in the combo box (so you don't get duplicates).
 * 4) Once you add the new point size, set the item data for the new item equal to the point size you are adding. For example, if you are adding the string &quot;15&quot; to the combo box, you need to set the item data of this new item to 15.

The following code fragment demonstrates the above steps:

  // 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 &quot;Font name&quot; combo box. if (wParam == cmb1) {              switch (HIWORD(lParam)) {                 case CBN_SETFOCUS: case CBN_KILLFOCUS: break; default: // Check to see if it is the font you are 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 you are looking // for. In this case, it is &quot;Courier New&quot;. if (strcmp(szBuf, &quot;Courier New&quot;) == 0) // It is the font you want. Post a message. PostMessage(hwnd, WM_ADDNEWPOINTSIZES, 0, 0L); }           }         break;

case WM_ADDNEWPOINTSIZES: // First look to see if you have already added point sizes to this // combo box. if (SendDlgItemMessage(hwnd, cmb3, CB_FINDSTRING, -1, (LPARAM)(LPCSTR)&quot;6&quot;) == CB_ERR) {           // Not found, add new point size. dwIndex = SendDlgItemMessage(hwnd, cmb3, CB_INSERTSTRING,                                           0, (LPARAM)(LPSTR)&quot;6&quot;);

// 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 query words:

Keywords : kbCmnDlg kbCmnDlgFont kbOSWinNT kbOSWin2000 kbSDKWin32 kbGrpDSUser kbOSWin

Issue type : kbhowto

Technology : kbWin32SDKSearch kbAudDeveloper kbWin3xSearch kbSDKSearch kbWin32sSearch kbWinSDKSearch kbWinSDK310