Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Text attributes for a TStatic control

Posted on 2000-04-13
1
Medium Priority
?
276 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 400 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

916 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