Solved

Text Size in Static Controls

Posted on 2003-11-26
6
722 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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…

770 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