tags:

views:

247

answers:

2

I have always used the default ListBox control with the property of OWNER DRAW set to NO. But now I need to set a fixed sized mono font since my formatted strings are not aligning up even though I have the default right aligned and necessary width padding set beyond the actual size of the digit string. My problem is I don't have a clue the simplest way to code for this nor have I ever coded for OWNER DRAW set to anything other than NO. Appreciate any input or examples or links. Additionally would like information on how would I check to even see what fixed mono width fonts are available on the system running my app? (C++ MFC, Visual Studio)

A: 

Don't know about CListBox, but in the standard Windows listbox, you can use the WM_SETFONT message to set the font of the control. CListBox probably wraps the native listbox, so if you can get the HWND of the CListBox, it should be easy to set the font of it using WM_SETFONT.

Patrick
Thank you for the reply I will try this out tonight when I get home. I seem to get from reading that I will have to change my listbox properties to OwnerDraw in order to change the font so I will have to learn all of that also.
RWB
+1  A: 

Declare a CFont object and init it with CFont::CreateFont.
"Courier New" is usually a good choice for fixed width fonts.

Use CListBox's SetFont() method (inherited from CWnd) to replace the default one.

Nick D
Thank you for the reply I will try this out tonight when I get home. I seem to get from reading that I will have to change my listbox properties to OwnerDraw in order to change the font so I will have to learn all of that also.
RWB