🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8895

Can't paint a static text

#8895
From: Ed Mulroy [TeamB]
Date: Mon, 30 Aug 2004 22:42
62 lines
2919 bytes
It's been so long since I played with dialog boxes that I'm rusty and 
I'm having trouble painting a static text control. Anyone have a clue 
as to what I am doing wrong?  (This is all API code, no VCL.)

The dialog box is a simple *.RC file dialog with a couple of static 
texts, a combo, a checkbox and three buttons.

Given
  HDC hdc = GetDC(hwnd);
  RECT rclient;
  RECT r;

  GetClientRect(hwnd, &rclient);
  r = rclient;
  r.right = somenumber; // yes, it's in range
  FillRect(hdc, &r, left_brush);
  r.left = r.right;
  r.right = rclient.right;
  FillRect(hdc, &r, right_brush);

Where left_brush is blue, CreateSolidBrush(RGB(0, 0, 128)) and
right brush is white, GetStockObject(WHITE_BRUSH)

There are white horizontal lines in the left part (when I tried a 
yellow brush for the right the white lines were there also)

So I used a memory DC and bitmap

  HDC hdcmem = CreateCompatibleDC(hdc);
  int savenum = SaveDC(hdc);
  int wide = rclient.right - rclient.left;
  int high =rclient.bottom - rclient.top;
  HBITMAP membmp = CreateCompatibleBitmap(hdc, wide, high);

  SelectObject(hdc, membmp);
  --same FillRect's as above but with memdc
  BitBlt(hdc, rclient.left, rclient,top, wide, high,
    hdcmem, 0, 0, SRCCOPY);

And now nothing is written.

However if I add this after the last FillRect in either configuration 
the number
shows just fine:

  SetBkMode(TRANSPARENT);
  char buf[32];
  wsprintf(buf, "%d", somenumber);
  TextOut(hdc, 0, 0, buf, lstrlen(buf)); // hdcmem for the other 
config

So I decided that the control must be painting its background and 
wiping out what I was doing.  To defend against that I subclassed the 
window, totally taking over WM_PAINT and WM_ERASEBKGND and doing 
CallWindowProc for all others (except for WM_DESTROY which is where I 
restore the window procedure addr with SetWindowLong but still do the 
CallWindowProc).

The results were unchanged.  Breakpoints verify that the subclassing 
code is executing.

.  Ed
Technical Details
Message-ID: <4133ad5e@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,a073ad797ba72502,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Ed Mulroy [TeamB]" <dont_email_me@invalid.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Can't paint a static text 
Date: Mon, 30 Aug 2004 18:42:12 -0400
Lines: 64
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
NNTP-Posting-Host: 12.161.27.61
Message-ID: <4133ad5e@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1093905758 12.161.27.61 (30 Aug 2004 15:42:38 -0700)
X-Authenticated-User: edmulroy
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail