Thread: WM_CTLCOLORSTATIC and a HBRUSH

  1. #1
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214

    WM_CTLCOLORSTATIC and a HBRUSH

    hi, im using a hbrush with ctlcolorstatic.
    the problem is that the color is not working right, here is the code.

    Code:
    		case WM_CTLCOLORSTATIC:		
    			SetBkColor((HDC)wParam , hBrush);
    			SetTextColor((HDC)wParam ,RGB(255,255,255));
    		
    			return ((LRESULT)hBrush);
    the background color of it seems to be changing right but the background color of the text is allways black.
    im getting 2 warnings and they are

    Code:
    'unsigned long ' differs in levels of indirection from 'struct HBRUSH__ *'
    'SetBkColor' : different types for formal and actual parameter 2
    im getting them for the SetBkColor line..im not to sure what they mean either.

    if some one could help me out with this problem it would be much appriciated.
    thanks
    Good Help Source all round
    Good help for win programmers
    you will probably find something in here
    this thing also helps

    if you have never tried any of the above then maybe you should, they help alot

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Take a closer look at the type required for the second parameter of SetBkColor.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214
    ok so to me it seems you cant use a hBrush with SetBkColor.
    is there any other way that this could be done with?
    Good Help Source all round
    Good help for win programmers
    you will probably find something in here
    this thing also helps

    if you have never tried any of the above then maybe you should, they help alot

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Quote Originally Posted by msdn
    COLORREF SetBkColor(
    HDC hdc, // handle to DC
    COLORREF crColor // background color value
    );
    'unsigned long ' differs in levels of indirection from 'struct HBRUSH__ *'
    'SetBkColor' : different types for formal and actual parameter 2
    ie. an HBRUSH is not a COLORREF. Use the RGB macro to generate COLORREF values (which, presumably, you did if your HBRUSH was returned from CreateSolidBrush) or use unsigned long values with format 0x00bbggrr where b,g and r refer to red, green and blue values respectively in the range 0x00 to 0xFF (0-255).

    edit: Alternatively, you can achieve the same text background as your returned hBrush by using:
    Code:
    SetBkMode(hdc,TRANSPARENT);
    in place of SetBkColor.
    Last edited by Ken Fitlike; 10-13-2004 at 08:13 AM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed