Solved

Text attributes for a TStatic control

Posted on 2000-04-13
1
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

627 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