Buttons over a static control

This is a discussion on Buttons over a static control within the Windows Programming forums, part of the Platform Specific Boards category; I'm having trouble to put two buttons over a static control, because I need a special color for that static ...

  1. #1
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    307

    Buttons over a static control

    I'm having trouble to put two buttons over a static control, because I need a special color for that static control...
    right now all my dialog background is white, with:
    Code:
    case WM_CTLCOLORDLG:
    {return (BOOL)GetStockObject(WHITE_BRUSH);}
    Now for the static background
    Code:
    case WM_CTLCOLORSTATIC:
    {
    if (hwControl == GetDlgItem(hwndDlg,IDC_FRAMEBUTTON))
    {
    SetBkMode(hdc,TRANSPARENT);
    return (BOOL)GetStockObject(DKGRAY_BRUSH);
    }
    return (BOOL)GetStockObject(NULL_BRUSH);
    }
    But the static is over the button, I need the opposite, the button over the static...any ideas?
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Joelito View Post
    I'm having trouble to put two buttons over a static control, because I need a special color for that static control...
    right now all my dialog background is white, with:
    Code:
    case WM_CTLCOLORDLG:
    {return (BOOL)GetStockObject(WHITE_BRUSH);}
    Now for the static background
    Code:
    case WM_CTLCOLORSTATIC:
    {
    if (hwControl == GetDlgItem(hwndDlg,IDC_FRAMEBUTTON))
    {
    SetBkMode(hdc,TRANSPARENT);
    return (BOOL)GetStockObject(DKGRAY_BRUSH);
    }
    return (BOOL)GetStockObject(NULL_BRUSH);
    }
    But the static is over the button, I need the opposite, the button over the static...any ideas?
    Yep... don't overlap windows controls with anything but a GROUPBOX. When the static control gets WM_PAINT it will draw right over the buttons...

    The solution is to use a GROUPBOX (The button control style with the line around it and a title string)... which is specifically designed as a background for buttons and other controls. It should also be the window parent for any controls you place inside it.

    To control it's colour you catch WM_CTLCOLORBUTTON and check it's handle before providing a brush.

    The hdc for WM_CTLCOLOR<whatever> is in the WPARAM and the LPARAM has the control's handle. And, this message needs a data return so don't cast the return to (BOOL) just return the brush.

    To check for the correct control you should use ...
    Code:
    if ((HWND) WPARAM == GetDlgItem(hwndDlg,IDC_FRAMEBUTTON))
    Substitute whatever varable name you gave the WPARAM... of course.

  3. #3
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    307
    @CommonTater: But is a dialog...all the controls have the dialog hwnd as parent
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    So... try it with the groupbox and leave the parent windows alone... see what happens. I do groupboxes in dialogs a lot (take a peek at the software on my website) and they work just fine with the Dialog as parents. It's when you start stacking other kinds of controls you have to get a bit fancy...

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Have you tried using SetWindowPos() [in the init/create handler] to ensure that the controls have the required z-order?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  2. Replies: 23
    Last Post: 07-09-2007, 04:49 AM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  4. Few Questions (Styles, Static Control)
    By Zeusbwr in forum Windows Programming
    Replies: 11
    Last Post: 04-15-2005, 04:13 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21