Thread: Child/Parent problem

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    193

    Child/Parent problem

    I have this:

    Code:
    HWND hWndGroupBox = CreateWindowEx(0, "BUTTON", "Search", WS_CHILD|WS_VISLBE|BS_GROUPBOX, 0, 0, 0, 0, hWnd, (HMENU)ID_GROUPBOX, hInst, NULL);
    CreateWindowEx(0, "BUTTON", "Search", WS_CHILD|WS_VISLBE|WS_TABSTOP, 0, 0, 0, 0, hWndGroupBox, (HMENU)ID_SEARCH, hInst, NULL);
    Simply, I have a button thats a child to a groupbox thats a child to my program. I was wondering how I get the message when someone clicks the button.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    BN_CLICKED notifications should be sent to the parent in the form of a WM_COMMAND; the main parent should get them but, if not, subclass the groupbox and handle its WM_COMMAND to get the BN_CLICKED notification.

    There's many previous examples of such notification handling so a board search should prove useful.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    It IS passed to the parent window's WM_COMMAND notification and wParam holds that button's identifier.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    So what am I doing wrong or am I misreading what you are saying:

    Code:
    switch(Message) {
    ...
    case WM_COMMAND:
         switch(LOWORD(wParam)) {
              case ID_GROUPBOX:
                   MessageBox(hWnd,"Clicked","Test",0);
                   break;
         }
         return true;
    ...
    }
    I'm just using that as test code until I get it working. I realize that I may have to add another switch statement to sort through which button is clicked and whatever, but this should still work shouldn't it?

    Thanks for your help so far.

  5. #5
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Group box doesn't send a message when it's clicked. It's not a button. ID_SEARCH is.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  6. #6
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    Thats my question then, how do I get the ID_SEARCH message because this isnt working because of the fact that it is a child to the groupbox:

    Code:
    switch(Message) {
    ...
    case WM_COMMAND:
         switch(LOWORD(wParam)) {
              case ID_SEARCH:
                   MessageBox(hWnd,"Clicked","Test",0);
                   break;
         }
         return true;
    ...
    }
    If I change the parent from hWndGroupBox to hWnd, that code works just fine, but I have the parent as hWndGroupBox, so that code isnt working, so I am wondering what I need to be doing.

  7. #7
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    As I mentioned previously, under this circumstance you should subclass(old article but still relevant) the groupbox, and handle its WM_COMMAND message.

    Once more, I suggest you search the board as the subject of subclassing has been discussed often in the past.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  8. #8
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    The only reason I didnt search before is because I'm not sure what I should be searching for because I wasnt sure where to start. I will take a look at that article and search the forum to see if I can figure it out.

    Thanks for all your help so far.

  9. #9
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    I just realized that the reason my program was running slow was because I was sending a lot of queries to my MySQL database and not because I had many many control things. The reason I originally was doing this was because I thought it would speed up my program and I'm sure it could, but it seems like a pain to have many different subclass functions for all the controls that are used as parents. Thanks for your help, but I think I'll stick with what I've got.

  10. #10
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I'm under the assumption that a group-box should not generally be used as a parent window. Controls should just be positioned above the group box, but still use the same parent window.

  11. #11
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    And I was under the assumption of the opposite that a groupbox should be a parent. I dont know for sure though because I'm not very experienced with this.

  12. #12
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    The name 'groupbox' has maybe led you to think of it as an automatic candidate as a parent for other controls but it's just a specialised button intended to act as a visual container for other controls. As such, it has limited functionality.

    If all you need to do is postion the control then it's probably less work to make the main window the parent, rather than subclass. If you you needed to add some functionality beyond what is offered by the control then subclassing is an option.

    For example, if you wished to create a unique type of control - a 'groupbox-button' control, for example - with specific functionality and look then I wouldn't see any problem with starting with a subclassed (or even superclassed) groupbox to achieve this, provided doing so was simpler than the alternative of just using the system controls with the main window as parent.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM