Thread: Creating a Group Box

  1. #1
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630

    Creating a Group Box

    I dont see what the hell im doing wrong in attempting to create a groupbox in staright Win32 api. I create the group box passing it the parent windows hwnd as the parent, and specify the BS_GROUPBOX on creation of the groupbox but it shows up as a freeking push button. Only styles specified are WS_CHILD and BS_GROUPBOX
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  2. #2
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    WS_CHILD | WS_VISIBLE | BS_GROUPBOX
    is what i create my groupboxes with and they seem to work just fine.
    My Website
    010000110010101100101011
    Add Color To Your Code!

  3. #3
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    I added WS_VISABLE and still im getting a push button as the control. I simply dont see WTF is going on, as the class name im using "BUTTON" as the documentation says, and only using WS_VISABLE | WS_CHILD | BS_GROUPBOX, if I change the BS_GROUPBOX to BS_PUSHBUTTON same exact button pops up. Im not using any extended styles or anything fancy.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Show us the code (the CreateWindowEx call).

  5. #5
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Code:
    hControl = CreateWindowEx(NULL, "BUTTON", strText.c_str(), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_GROUPBOX, XPos, YPos, XSize, YSize, hParentWnd, (HMENU)(cCONTROLID),hInst,NULL);
    strText = "GroupBoxTest" and it shows up in the middle of the group box as it would on a push button.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    WS_TABSTOP seems to be a superfluous style for a groupbox. The first parameter to CreateWindowEx is a numeric type (DWORD), not a pointer so you should use zero for that and not NULL. Other than that it looks okay(I can't test it as I'm not using windows just now).
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Using WS_TABSTOP is a habit of mine when creating controls Anyways I tracked the bug down finally to a default value that was being set in the controls initialization of its class. But onto another question do group boxes need to be owner drawn?
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    No, but sometimes it might be useful to create them with the WS_EX_TRANSPARENT extended window style, and/or WS_CLIPSIBLINGS window style.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  9. #9
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Hmm, well I got the group box to create but its completly transparent showing what is under the window when it was created (i.e. its showing the part of visual stuidio in it, only styles used are BS_GROUPBOX, WS_CHILD, and WS_VISIBLE.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  10. #10
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Interesting, the main window was not initially visable so when the group box is created it was having an issue in creation making it transparent, adding WS_VISIBLE to the main window fixed the problem.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  11. #11
    Registered User
    Join Date
    Apr 2006
    Posts
    137
    Quote Originally Posted by Ken Fitlike
    No, but sometimes it might be useful to create them with the WS_EX_TRANSPARENT extended window style, and/or WS_CLIPSIBLINGS window style.
    yes that took me 2 days to figure out :P

    My boxes were transparent, but i never thought setting a transparent style would make it not transparent lol wow

  12. #12
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Im now encountering a new problem with my group box. When the application is minimized and brought back up the group box has become transparent.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  13. #13
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Hmm, added WS_EX_TRANSPARENT like you said ken and boom no more problems with it becoming transparent, but I just dont understand why in the hell you would have to do that any insight?
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  14. #14
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    It's the order in which controls are drawn - if you have time/can be bothered make a small, test application and add controls one at a time within a groupbox with various styles and extended styles and observe the behavior. Creating other controls with WS_CLIPSIBLINGS is possibly an option, too, particularly if they're to be grouped within or near a groupbox.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. How to program a "back" button with MFC
    By 99atlantic in forum Windows Programming
    Replies: 3
    Last Post: 04-26-2005, 08:34 PM
  3. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM