Click to See Complete Forum and Search --> : Colored Text staying
SteveCRM
Jan 20th, 2003, 01:30 PM
in WM_COLORBTN I am using this code
if(bmatrix[fx][fy]=="green")
{
SetTextColor((HDC)wParam, RGB(0, 255, 0));
SetBkMode((HDC)wParam, TRANSPARENT);
GetClientRect((HWND)lParam, &rt);
DrawText((HDC)wParam, TEXT("hello"), -1, &rt, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
return (long)hBrush2;
}
(sorry about the alignment)
it works ok, but whenever I push other buttons on my screen, it goes away, and doesn't come back, is there any way to make the text permanent? :confused:
Chris
Jan 20th, 2003, 06:48 PM
you need to use the WM_CTLCOLORBTN
case WM_CTLCOLORBTN:
// Change the Button control background color
// Ref.
// wParam - handle to static control DC (HDC)
// lParam - handle to static control handle (HWND)
// Set the return value
return (long)hBrush;
SteveCRM
Jan 20th, 2003, 09:43 PM
Im sorry i typed wrong, I am using WM_CTLCOLORBTN
Im using it in a game of memory, and I must make it using colors (matching "Yellow" to a yellow button) if you need a better understand of what i'm trying to accomplish.
here is my full segment of code
bmatrix holds all the information for a memroy game
board is the actual matrix of buttons used in the game
I'm using apstring (don't kill me)
case WM_CTLCOLORBTN:
// Change the Button control background color
// Ref.
// wParam - handle to static control DC (HDC)
// lParam - handle to static control handle (HWND)
for(fy=0; fy<2; fy++)
{
for(fx=0; fx<5; fx++)
{
if ((HWND)lParam == board[fx][fy])
{
if(bmatrix[fx][fy]=="green")
{
SetBkColor((HDC)wParam, RGB(0,255,0));
GetClientRect((HWND)lParam, &rt);
DrawText((HDC)wParam, TEXT(" "), -1, &rt, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
return (long)hBrush2;
}
if(bmatrix[fx][fy]=="red")
{
SetBkColor((HDC)wParam, RGB(255,0,0));
GetClientRect((HWND)lParam, &rt);
DrawText((HDC)wParam, TEXT(" "), -1, &rt, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
return (long)hBrush2;
}
if(bmatrix[fx][fy]=="blue")
{
SetBkColor((HDC)wParam, RGB(0,0,255));
GetClientRect((HWND)lParam, &rt);
DrawText((HDC)wParam, TEXT(" "), -1, &rt, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
return (long)hBrush2;
}
if(bmatrix[fx][fy]=="yellow")
{
SetBkColor((HDC)wParam, RGB(255,255,0));
GetClientRect((HWND)lParam, &rt);
DrawText((HDC)wParam, TEXT(" "), -1, &rt, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
return (long)hBrush2;
}
if(bmatrix[fx][fy]=="cyan")
{
SetBkColor((HDC)wParam, RGB(0,255,255));
GetClientRect((HWND)lParam, &rt);
DrawText((HDC)wParam, TEXT(" "), -1, &rt, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
return (long)hBrush2;
}
}
}
}
return 0;
again im sorry about alignment
it shows up briefly, and stays if I hold the mouse button down...but won't stay :confused:
CornedBee
Jan 21st, 2003, 10:40 AM
I fear you'll have to subclass the buttons and catch the WM_PAINT message. Don't forget to let the button draw first (by calling CallWndProc), and only then you draw what you want.
SteveCRM
Jan 21st, 2003, 04:17 PM
err...sorry but i really have no idea how to do that...:( no other way? im guessing there isn't really a way of putting that in a loop until another button is pushed. I don't really care if its crap code or anything, but as long as color comes up on a button :) Do you think i'm going about it with a wrong method? or would this definately be easiest?
CornedBee
Jan 22nd, 2003, 04:40 AM
I think it's the only way. You see, a button doesn't want anyone to draw on it's surface.
You could use ownerdraw buttons. But then you loose the typical button look.
Chris
Jan 22nd, 2003, 06:51 AM
but you still can have 2 bitmap which act as a base image for you owner draw button and this image will having the typical button look.
Although this seen a lot of work, but it still archieve your goal :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.