Text Color & Style Settings

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rsteph
    New Member
    • Oct 2006
    • 71

    Text Color & Style Settings

    This is, I'm sure, and easy question for most. I am a moderate C/C++ programmer in console based programs, I am looking to teach myself windows based programming though. I'm going through a book I bought and trying all of the exercises it gives to help me brush up on things.

    One things I'm curious about, but can't find in the book, is how to change text color and style. I've got a character pointer with the text "Hello World" stored in it, then I'm drawing it into a box with the following line:

    DrawText(hdc, szHello, strlen(szHello) , &rt, DT_LEFT);

    If I wanted to change the color of the text, what would I do to accomplish this?

    Also, can anyone suggest some websites with useful tutorials that I should bookmark for references?

    Any help would be greatly appreciated.
  • Studlyami
    Recognized Expert Contributor
    • Sep 2007
    • 464

    #2
    Use the function SetTextColor( hdc, COLORREF); This will set the color of the font for a specific device context.

    As for web sites for information Are you wanting MFC or WIN32?

    www.codeproject.com has a lot of great tutorials are articles for both.
    www.functionx.com has a lot of information on MFC items. It also contains some information on WIN32 as well.
    www.msdn.com does it really need an explanation.

    If your using WIN32 i recommend the book "Programmin g Windows" by Charles Petzold. If your using MFC I believe there is plenty of web resources for it, but learning some WIN32 wouldn't hurt.

    Comment

    • Studlyami
      Recognized Expert Contributor
      • Sep 2007
      • 464

      #3
      Ahh I missed the styles part. For changing the styles you are going to want to creat a font object (createfont(. . .), there a several other ways for getting a font object google them) When you create the font you can specify all kinds of different styles. Look up createfont on msdn.com. You will also need to apply the font to the hdc. SelectObject(hd c, font).

      Comment

      • rsteph
        New Member
        • Oct 2006
        • 71

        #4
        That worked thank you. And thank you for the sites.

        Comment

        Working...