Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WIN32 GUI Static Control Background color

507 views
Skip to first unread message

Bob Piskac

unread,
Mar 22, 2003, 9:31:59 PM3/22/03
to
How do I make the static control background color the same color? Right now
I have a white background on the left and right hand sides of the text.

#include <windows.h>
#include <stdio.h>

#define ID_TEXT_TITLE 1001

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);

int WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine,
int iCmdShow)
{
static TCHAR szAppName[] = "TestApp";
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
int iWidth, iHeigth;

wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); //(HBRUSH)
GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
iWidth = GetSystemMetrics(SM_CXSCREEN);
iHeigth = GetSystemMetrics(SM_CYSCREEN);


if (!RegisterClass (&wndclass)) {
MessageBox (NULL, "This program requires Windows!", szAppName,
MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, // window class name
"Test Application", // window caption
WS_OVERLAPPEDWINDOW, // window style
iWidth - iWidth/2 - 598/2, // initial x position
iHeigth - iHeigth/2 - 104, // initial y position
598, // initial x size
104, // initial y size
NULL, // parent window
handle
NULL, // window menu handle
hInstance, // program instance
handle
NULL) ; // creation parameters

ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;

while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
static HWND st_title;
int iControlId;
static HBRUSH hBrushStatic ;

switch (message){
case WM_CREATE : st_title = CreateWindow ("static", "This line has
white background Get rid of it!",
WS_CHILDWINDOW | WS_VISIBLE | SS_CENTER,
23, 16, 598 - 46, 16,
hwnd, (HMENU) ID_TEXT_TITLE,
(HINSTANCE) GetWindowLong (hwnd,
GWL_HINSTANCE),
NULL) ;
hBrushStatic = CreateSolidBrush
(GetSysColor(COLOR_BTNHIGHLIGHT)) ;
return 0 ;
case WM_PAINT : //hdc = BeginPaint (hwnd, &ps) ;
//GetClientRect (hwnd, &rect) ;
//DrawText (hdc, "Hello, Windows 98!", -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
//EndPaint (hwnd, &ps) ;
return 0 ;
case WM_CTLCOLOREDIT :
case WM_CTLCOLORBTN :
case WM_CTLCOLORDLG :
case WM_CTLCOLORSTATIC : iControlId = GetWindowLong ((HWND) lParam,
GWL_ID) ;

switch(iControlId){
case ID_TEXT_TITLE: SetTextColor ((HDC)
wParam, RGB(0,0,0)) ;
SetBkColor ((HDC)
wParam, RGB(125,125,125));
return (LRESULT)
hBrushStatic ;
break;
}

break ;


case WM_DESTROY: DeleteObject (hBrushStatic) ;
PostQuitMessage (0) ;
return 0 ;
}

return DefWindowProc (hwnd, message, wParam, lParam) ;
}


Josce

unread,
Mar 23, 2003, 7:52:06 AM3/23/03
to
>How do I make the static control background color the same color? Right
now
>I have a white background on the left and right hand sides of the text.


WM_CREATE
hNewStaticBrush = CreateSolidBrush (RGB(128,128,128)) ;

and

case WM_CTLCOLORSTATIC :
SetBkMode((HDC)wParam, TRANSPARENT);
SetTextColor((HDC) wParam, RGB(0,0,128));
return (LRESULT) hNewStaticBrush ;


HTH,

Josce


Bob Piskac

unread,
Mar 23, 2003, 11:44:59 AM3/23/03
to
Thanks it works great. When I move my window the static control text
disappears. What do I do to make sure I redraw the control?

"Josce" <Jos...@netscape.net> wrote in message
news:b5kase$rjp$1...@www.scitechsoft.com...


> >How do I make the static control background color the same color? Right
> now
> >I have a white background on the left and right hand sides of the text.

[SNIP]


Bob Piskac

unread,
Mar 23, 2003, 2:30:58 PM3/23/03
to
I fixed it. I had a bug.

"Bob Piskac" <b...@noSpampbsoftware.com> wrote in message
news:b5ko9t$1dp$1...@www.scitechsoft.com...

0 new messages