Solved

Text Size in Static Controls

Posted on 2003-11-26
6
736 Views
Last Modified: 2013-12-03
How does one set the text size in a static control when using the TextOut method ? I have been using the following wm_ctlcolorstatic message and it works fine except for the text size.

         case WM_CTLCOLORSTATIC:
    {
                         HDC hdcStatic ;
                         hdcStatic=GetDC(hwndSsel );
                         SetTextColor(hdcStatic, RGB(250,0,0));

           //      SetBkColor(hdcStatic,RGB(0,0,0));
                         SetBkMode(hdcStatic,TRANSPARENT);
                         TextOut(hdcStatic,14,10,"2",1);
        
        return (LONG)br_back;
    }
    break;
0
Comment
Question by:librazone
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:Daij-Djan
ID: 9836953
Use a font with the drawtext function.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9843840
Unless you need to change the font on-the-fly, it's easiest to simpley create the HFONT and send a  WM_SETFONT message to the STATIC control early on (e.g., in your WM_INITDIALOG handler.  

You can use CreatePointFont() to obtain the desired HFONT.

-- Dan
0
 
LVL 1

Author Comment

by:librazone
ID: 9843943
Well I was using the WM_SETFONT before I decided to color the background of the static control and it worked ok.As soon as I started using the WM_CTLCOLORSTATIC with the device context for the control the WM_SETFONT no longer worked.Does the WM_SETFONT message work when using the TextOut method.
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 49

Accepted Solution

by:
DanRollins earned 70 total points
ID: 9844039
The problem is that you are drawing the text yourself (with the TextOut call).  

You should let the defualt handler draw the text and it will use the font that has been asigned to it.  All you need to do in you  WM_CTLCOLORSTATIC is setup the HDC.  By the way, the HDC is passed in as the wParam value.  So...

      case WM_CTLCOLORSTATIC:
      {
            HDC hdc= (HDC)wParam;
            SetTextColor( hdc, RGB(250,0,0));
            SetBkMode(    hdc,TRANSPARENT);
            return (LONG)br_back;
      }
-- Dan
0
 
LVL 1

Author Comment

by:librazone
ID: 9845386
Yeah well the problem is that the text changes in these statics.If it didnt I would simply use a bitmap and draw that to the control as I have done for my other statics.The whole problem is with the text background color.If I use HFONT,WM_SETFONT,WM_CTLCOLORSTATIC and SetdlgItemInt the background color is ok but the text background color remains white.If I use TextOut everything is ok except I would like to increase the size of the text just a bit.Actually I could leave it as is because the readability is ok but I was wondering what that size is that TextOut is using.This has become an interesting little problem.
0
 
LVL 1

Author Comment

by:librazone
ID: 9845426
OK I just got it to work.. the problem was with my creating separate device contexts for the statics.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question