Computing.Net > Forums > Programming > Changing Font in TextBox object (VC++)

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Changing Font in TextBox object (VC++)

Reply to Message Icon

Name: Dennis Sedov
Date: May 15, 2002 at 18:01:05 Pacific
Comment:

Im creating a tect box by invoking the following command:

hServerLog = CreateWindowEx(WS_EX_CLIENTEDGE,
"EDIT",
"",
WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_READONLY|ES_LEFT|ES_MULTILINE|ES_AUTOVSCROLL,
0, 0,
491,250,
hWnd,
NULL,
hInst,
NULL);

How do I change the default font of that textbox into somthing else?



Sponsored Link
Ads by Google

Response Number 1
Name: Jeff
Date: May 15, 2002 at 19:51:20 Pacific
Reply:

You can't change the default font for a Win32 control; it defaults to the default system font. However, you can change the font of any control, by resetting it anytime after creation (calling CreateWindowEx).

Some people prefer to wait until the ctrl's parent window receives the WM_CTLCOLOREDIT message. It is sent when the ctrl is first drawn, at which time its colors and font can be set.

Anyway, you'll need to create a font, or use an existing one, and set it like this:

SendMessage(hServerLog, WM_SETFONT, (WPARAM)hMyFont, 0);

where hMyFont is a handle to a font, such as one created by the CreateFontIndirect() function. For example:

LOGFONT lf;

memset(&lf, 0, sizeof(LOGFONT);
lf.lfWeight = FW_NORMAL;
lf.lfHeight = 20; //in pixels
lf.lfFaceName = "Arial";

HFONT hMyFont = CreateFontIndirect(&lf);

There are other options with the zany LOGFONT structure, but that's beyond this post.


0
Reply to Message Icon

Related Posts

See More


C++: Convert Multibyte bu... aku



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Changing Font in TextBox object (VC++)

C++, changing font www.computing.net/answers/programming/c-changing-font/2557.html

How to change font and background c www.computing.net/answers/programming/how-to-change-font-and-background-c/10470.html

VBA in Business Objects www.computing.net/answers/programming/vba-in-business-objects/2265.html