Solved

Text attributes for a TStatic control

Posted on 2000-04-13
1
267 Views
Last Modified: 2013-12-26
How could I ensure text attributes i.e. text color and background color for a TStatic control created by a statement like
tst = new TStatic(this,id,text,x,y,w,h);
Actually I have always black text on grey background while the parent window has black text on white background. I would like to have black on white in a control too but I can't obtain this.
Thank you in advance fo a response
0
Comment
Question by:rainette
1 Comment
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 100 total points
ID: 2718885
You must trap WM_CTLCOLOR message.
Next is small example. Pay attention to
EvCtlColor function :

#include <owl/pch.h>
#include <owl/applicat.h>
#include <owl/framewin.h>
#include <owl/static.h>

static TStatic* hStatic;
//
// class TTestWindow
// ~~~~~ ~~~~~~~~~~~
class TTestWindow : public TWindow {
  public:
    TTestWindow(TWindow* parent = 0);
   HBRUSH EvCtlColor (HDC hDC, HWND hWndChild, UINT ctlType);
   DECLARE_RESPONSE_TABLE(TTestWindow);
};
DEFINE_RESPONSE_TABLE1(TTestWindow, TWindow)
  EV_WM_CTLCOLOR,
END_RESPONSE_TABLE;

HBRUSH TTestWindow::EvCtlColor (HDC hDC, HWND hWndChild, UINT ctlType)
{
  if (hWndChild == hStatic->HWindow)
    {
      static HBRUSH whiteBrush = (HBRUSH) GetStockObject (WHITE_BRUSH);

      TDC DC (hDC);
      DC.SetTextColor (TColor::LtRed);
      return ( whiteBrush );
    }
  return ( TWindow::EvCtlColor (hDC, hWndChild, ctlType) );
}

//
//
//
TTestWindow::TTestWindow(TWindow* parent)
:
  TWindow(parent)
{
  struct {
    char*  Text;
    uint32 And;
    uint32 Or;
  }
  ctlInfo[] = {
    { "Default",     0xFFFFFFFFL, 0 },
    { "SS_SIMPLE",      ~SS_LEFT, SS_SIMPLE },
    { "SS_LEFT",        ~SS_LEFT, SS_LEFT },
    { "SS_NOPREFIX",    ~SS_LEFT, SS_NOPREFIX },
    { "SS_CENTER",      ~SS_LEFT, SS_CENTER },
    { "SS_RIGHT",       ~SS_LEFT, SS_RIGHT },
    { "SS_BLACKRECT",   ~SS_LEFT, SS_BLACKRECT },
    { "SS_GRAYRECT",    ~SS_LEFT, SS_GRAYRECT },
    { "SS_BLACKFRAME",  ~SS_LEFT, SS_BLACKFRAME },
    { "SS_GRAYFRAME",   ~SS_LEFT, SS_GRAYFRAME },
    { "SS_WHITEFRAME",  ~SS_LEFT, SS_WHITEFRAME },
#if defined(BI_PLAT_WIN32)
    { "SS_ETCHEDHORZ",  ~SS_LEFT, SS_ETCHEDHORZ },   //0x00000010L
    { "SS_ETCHEDVERT",  ~SS_LEFT, SS_ETCHEDVERT },   //0x00000011L
    { "SS_ETCHEDFRAME", ~SS_LEFT, SS_ETCHEDFRAME },   //0x00000012L
#endif
  };

  Attr.W = 390;
  Attr.H = 460;

#if defined(BI_PLAT_WIN32)
  Attr.ExStyle |= WS_EX_CONTROLPARENT;
#endif

  hStatic = new TStatic(this, -1, ctlInfo[0].Text, 20, 20 + 0*30, 150, 24, 0);

  SetBkgndColor(TColor::Sys3dFace);
}


//
// class TTestApp
// ~~~~~ ~~~~~~~~
class TTestApp : public TApplication {
  public:
    TTestApp() : TApplication() {}
    void InitMainWindow() {
      SetMainWindow(new TFrameWindow(0, "Static Control Tester", new TTestWindow, true));
    }
};

int
OwlMain(int /*argc*/, char* /*argv*/ [])
{
  TTestApp app;
  return app.Run();
}

I hope, it helps. Alex
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

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

912 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

20 Experts available now in Live!

Get 1:1 Help Now