Results 1 to 7 of 7

Thread: Colored Text staying

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    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?

  2. #2
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    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

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    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

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    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?

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  7. #7
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    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
  •  



Click Here to Expand Forum to Full Width