|
-
Jan 20th, 2003, 02:30 PM
#1
Thread Starter
Frenzied Member
Colored Text staying
in WM_COLORBTN I am using this code
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?
-
Jan 20th, 2003, 07:48 PM
#2
PowerPoster
you need to use the WM_CTLCOLORBTN
PHP Code:
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;
-
Jan 20th, 2003, 10:43 PM
#3
Thread Starter
Frenzied Member
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)
Code:
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
-
Jan 21st, 2003, 11:40 AM
#4
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 21st, 2003, 05:17 PM
#5
Thread Starter
Frenzied Member
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?
-
Jan 22nd, 2003, 05:40 AM
#6
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 22nd, 2003, 07:51 AM
#7
PowerPoster
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|