Solved

Text Size in Static Controls

Posted on 2003-11-26
6
716 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using Powershell in Visual Studio 2015 SP1 Community Edition 4 77
Visual Studio Debugging 3 121
Need to impress with my knowledge of .NET 5 81
dialer.exe 4 58
This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

15 Experts available now in Live!

Get 1:1 Help Now