Thread: Static control color change

  1. #1
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768

    Static control color change

    I've created a static text control using the resource.
    I have two questions:

    1) Is there a way to apply a color to the static within the resource?
    2) How can I change the color after the static control was already created?


    Thank you.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  2. #2
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    1) not sure
    2) you catch the WM_CTLCOLORSTATIC message

  3. #3
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    Syntax
    Code:
    WM_CTLCOLORSTATIC
    
        WPARAM wParam
        LPARAM lParam;
    Parameters

    wParam
    Handle to the device context for the static control window.
    lParam
    Handle to the static control.

    Return Value

    If an application processes this message, the return value is a handle to a brush that the system uses to paint the background of the static control.
    * Can I use the lParam to match the handle to the handle of the static control I wish to paint?

    * Also, I've tried to color the text itself without the background color but it doesn't work...
    Code:
            case WM_CTLCOLORSTATIC:
                    SetTextColor((HDC)wParam, RGB(0, 255, 0));
                    return((HBRUSH)0);
    Last edited by Devil Panther; 08-08-2005 at 10:54 AM.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  4. #4
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Quote Originally Posted by Devil Panther
    Also, I've tried to color the text itself without the background color but it doesn't work...
    To return a NULL brush, use GetStockObject(NULL_BRUSH).
    You should also call SetBkMode to make the background of the text (not the static control) transparent.

    Code:
        case WM_CTLCOLORSTATIC:
          {
            HDC  hdc  = (HDC)  wParam ;
            HWND ctrl = (HWND) lParam ;
      
            SetBkMode( hdc, TRANSPARENT );
            SetTextColor( hdc, RGB(0, 255, 0) );
      
            return (LRESULT)GetStockObject(NULL_BRUSH); 
          }

  5. #5
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    Something is not working...
    The result of the code is black text on a white background
    Last edited by Devil Panther; 08-10-2005 at 08:34 AM.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  6. #6
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Hmm, it seemed to work for me when I posted that snippet yesterday.
    Mind posting your code?

  7. #7
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    oops, got the lParam and wParam mixed up
    it works fine now, thank you.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  3. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  4. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM