Results 1 to 4 of 4

Thread: Changing a Button's Color

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    183

    Changing a Button's Color

    I want to change the color of a button in a dialogbox, I have been doing the following but it doesn't work, I stepped through and the cases do get each called, but it has no effect on the buttons.

    <code>
    case WM_CTLCOLORBTN:
    switch((GetWindowLong((HWND)lParam,GWL_ID))){
    case IDC_LINE1:
    SetBkColor((HDC) wParam,RGB(255,0,0));
    SetTextColor((HDC)wParam, RGB(255,255,255));
    case IDC_LINE2:
    SetBkColor((HDC) wParam,RGB(0,255,0));
    SetTextColor((HDC)wParam, RGB(255,255,255));
    case IDC_LINE3:
    SetBkColor((HDC) wParam,RGB(0,0,255));
    SetTextColor((HDC)wParam, RGB(255,255,255));
    }
    return ((LRESULT) CreateSolidBrush(RGB(0,0,0)));
    </code>

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Since your function probably is a DialogProc, the return value is a BOOL and you should return TRUE if you handle the message. The real return value (the LRESULT of a WndProc) is accessed by
    SetWindowLong(hDlg, DWL_MSGRESULT, (LONG)result);

    This probably won't solve your main problem though.
    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    183
    Nope that doesn't help at all and nope you shouldn't return TRUE regardless, have a look at the help.

    I changed the buttons in the VC++ compiler for the dialog boxes so they are owner draw and the follwing code will change the color, but now the text has disapeared regardless of what color I set the text color it won't come back.

    <CODE>
    case WM_CTLCOLORBTN:/*getting called twice?*/
    switch((GetWindowLong((HWND)lParam,GWL_ID))){
    case IDC_LINE1:
    SetBkColor((HDC) wParam,RGB(255,0,0));
    SetTextColor((HDC)wParam, RGB(255,255,255));
    temp = GetBkColor((HDC)wParam);
    break;
    case IDC_LINE2:
    SetBkColor((HDC) wParam,RGB(0,255,0));
    SetTextColor((HDC)wParam, RGB(255,255,255));
    temp = GetBkColor((HDC)wParam);
    break;
    case IDC_LINE3:
    SetBkColor((HDC) wParam,RGB(0,0,255));
    SetTextColor((HDC)wParam, RGB(255,255,255));
    temp = GetBkColor((HDC)wParam);
    break;
    }
    return ((LRESULT) CreateSolidBrush(temp));
    </CODE>

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    owner draw buttons don't have text, they need to be drawn completely by you.

    I did look that thing up in help, it's in the topic "DialogProc".

    And you shouldn't create a new brush every time, you should create one for each button at dialog initialization and destroy them at dialog destruction.
    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.

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