Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Text attributes for a TStatic control

Posted on 2000-04-13
Medium Priority
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
Question by:rainette
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

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 {
    TTestWindow(TWindow* parent = 0);
   HBRUSH EvCtlColor (HDC hDC, HWND hWndChild, UINT ctlType);

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)
  struct {
    char*  Text;
    uint32 And;
    uint32 Or;
  ctlInfo[] = {
    { "Default",     0xFFFFFFFFL, 0 },
    { "SS_SIMPLE",      ~SS_LEFT, SS_SIMPLE },
    { "SS_LEFT",        ~SS_LEFT, SS_LEFT },
    { "SS_CENTER",      ~SS_LEFT, SS_CENTER },
    { "SS_RIGHT",       ~SS_LEFT, SS_RIGHT },
#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

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

#if defined(BI_PLAT_WIN32)

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


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

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

I hope, it helps. Alex

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

715 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