Solved

Text Size in Static Controls

Posted on 2003-11-26
6
729 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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