kevin@msa3b.UUCP (Kevin P. Kleinfelter) (08/25/90)
How does one set the font for a listbox? The only thing I can find about changing fonts in TFM is for TextOut. i.e. SelectObject (hDC, hFont); TextOut (hDC, ...); The only way I can see to use this information would be with an owner-draw listbox (and that LOOKS like a lot of work to me). If I HAVE to, I'll change the font for the whole application. How does one do that? For each of these cases, it seems as though I ought to be able to SelectObject (display_context_used_by_window_or_application, hFont); but I do not know how to get at the display context (i.e. GetDC seems to be creating a NEW DC, and not returning the address of the DC to be used by the window or application). -- Kevin Kleinfelter @ Dun and Bradstreet Software, Inc (404) 239-2347 {emory,gatech}!nanovx!msa3b!kevin "Don't hold your finger on the button if the motor ain't goin' roundy-roundy."
kensy@microsoft.UUCP (Ken SYKES) (08/27/90)
In article <1355@msa3b.UUCP> kevin@msa3b.UUCP (Kevin P. Kleinfelter) writes: >How does one set the font for a listbox? The only thing I can find >about changing fonts in TFM is for TextOut. i.e. > SelectObject (hDC, hFont); > TextOut (hDC, ...); > >The only way I can see to use this information would be with an owner-draw >listbox (and that LOOKS like a lot of work to me). Yes, you will have to do an owner-draw listbox. It is a little more work but not terribly bad (esp. since you only want to change the font) The interface to the listbox still works the same (LB_ADDSTRING, LB_FINDSTRING, etc.) but you need to provide drawing code. As an aside, the only Windows-provided control that you can change the font in (that I know of) is a dialog box. In this case add the DS_SETFONT attribute to the dialog style then send a WM_SETFONT message in the dialog's WM_INITDIALOG code. [Dang VI. How do you join lines again... ;-) ] Sorry it isn't easier. Ken Sykes Disclaimer: The above opinions are solely my own.
carlc@mars.SanDiego.NCR.COM (Carl Christofferson) (08/27/90)
In article <1355@msa3b.UUCP> kevin@msa3b.UUCP (Kevin P. Kleinfelter) writes: >How does one set the font for a listbox? The only thing I can find >about changing fonts in TFM is for TextOut. i.e. > SelectObject (hDC, hFont); > TextOut (hDC, ...); > If your list box is in a dialog box, its real simple. First, get a handle to the desired font, hDesiredFont = GetStockObject (XXX_FONT); // I used SYSTEM_FIXED_FONT Then, in the WM_INITDIALOG in your dialog box code, send a WM_SETFONT message to the list box: case WM_INITDIALOG: SendDlgItemMessage (hDlg, ID_CONTROL, WM_SETFONT, hDesiredFont, 0L); // ID_CONTROL is the ID you gave to your list box, ie IDL_LISTBOX // other code as desired break; That's it! Hope this helps. Carl Christofferson carlc@mars.SanDiego.NCR.COM disclaimer: Any opinions expressed are entirely my own ...
marc@metapyr.UUCP ( The Karate Kid ) (08/28/90)
In article <2915@ncr-sd.SanDiego.NCR.COM> carlc@mars.SanDiego.NCR.COM (Carl Christofferson) writes: >In article <1355@msa3b.UUCP> kevin@msa3b.UUCP (Kevin P. Kleinfelter) writes: >>How does one set the font for a listbox? The only thing I can find >>about changing fonts in TFM is for TextOut. i.e. >> SelectObject (hDC, hFont); >> TextOut (hDC, ...); >> > >If your list box is in a dialog box, its real simple. First, get a handle >to the desired font, > hDesiredFont = GetStockObject (XXX_FONT); // I used SYSTEM_FIXED_FONT > >Then, in the WM_INITDIALOG in your dialog box code, send a WM_SETFONT message >to the list box: > case WM_INITDIALOG: > SendDlgItemMessage (hDlg, ID_CONTROL, WM_SETFONT, hDesiredFont, 0L); > // ID_CONTROL is the ID you gave to your list box, ie IDL_LISTBOX > // other code as desired > break; > >That's it! Hope this helps. > >Carl Christofferson >carlc@mars.SanDiego.NCR.COM >disclaimer: Any opinions expressed are entirely my own ... The control does not have to be in a dialog box! The WM_SETFONT message can be sent to any window at any time! I've done this to show a change of focus for MDI child windows and the title bar (pretty cool effect). Just load the desired font and then force a repaint of the frame (WM_NCPAINT) and voila a new font in the title bar. The WM_PAINT with the new font from WM_SETFONT will cause the contents of a control to be painted correctly. Windows has come a long way with this feature. BTW, I'm also VERY glad to see that they added the extended dialog box call. I hate using file statics or globals to configure complex dialogs. Now I can pass the handle to a nice structure describing the configuration. "Isn't that special?!" I hope this is the last of this. Remember a window is a window is a window. Pretty much anything you can do to a window of your own class can be done to a window of the standard classes. AND you can always subclass to do the things that the standard classes can't do. Marc Paige ------------------------------------------------------------------------------ "tired and shagged out from a prolonged squawk" - mpfc the parrot sketch