Solved

Text Size in Static Controls

Posted on 2003-11-26
6
711 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now