Skip to main content
GameDev.net gamedev.net
🔒 Locked

Transparent font / static control

Started by smidge_tech Dec 26, 2001 at 9:22 AM 3 replies 1.3k views
Original Post
smidge_tech
smidge_tech
This is a simple problem but for some reason it's annoying me... I have a few static controls on my window, and I've changed the background window colour to a nice pale blue colour... However the background behind the lettering of the text in each static control is still painted in the original colour... According to the Platform SDK, I have to handle the WM_CTLCOLORSTATIC message, which can be used to set the background colour. So this is what I have:
  
// g_App.GetBckBrush() returns the HBRUSH I'm using.

// rcRect is just a RECT structure.

case WM_CTLCOLORSTATIC:
    // A static control is about to be drawn...

    GetWindowRect((HWND)lParam, &rcRect);
    FillRect((HDC)wParam, &rcRect, g_App.GetBckBrush());
    return((LRESULT)g_App.GetBckBrush());
  
... but when I do that it redraws the background behind the text as plain white, whatever brush I supposedly paint it with in this snippet of source code. Weird. Have I missed something? Thanks, ======== Smidge ======== Edited by - smidge_tech on December 26, 2001 10:24:55 AM
--Mr Smidge
Shannon Barber
Shannon Barber
You can try finding where MFC registers the window class, and use your brush instead of the default one there...
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Zeblar Nagrim
Zeblar Nagrim
try this (works for me):

  
// g_App.GetBckBrush() returns the HBRUSH I''m using.

// rcRect is just a RECT structure.

case WM_CTLCOLORSTATIC:
SelectObject((HDC) wParam, g_App.GetBckBrush());

//

// Set the text background color and background mode.

SetBkMode((HDC) wParam, TRANSPARENT);
SetBkColor((HDC) wParam, g_App.GetBkColor());

//

// Set the text foreground color.

SetTextColor((HDC) wParam, g_App.GetTextColor());

//

// Return the control background brush.

return (long) g_App.GetBckBrush();
break;




Zeblar Nagrim, Lord of Chaos
smidge_tech
smidge_tech
Thanks Zeblar, works perfect

========
Smidge
========
--Mr Smidge
Zipster
Zipster
Just to clarify what made the difference - you needed to set the background mode to TRANSPARENT so that anything in the background doesn''t get overdrawn except where the actual text is.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.