Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Custom Component Newbie Question

Custom Component Newbie Question

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelpc++
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    crewchill
    wrote on last edited by
    #1

    Hi all. First, thanks for all the cool articles around. Really helpful. Second, I got a dumb question: I created a CStatic-derived class because I hate the normal groupbox MFC provided. Lets call it CBetterGroupbox. I put in CBetterGroupbox::addMember(CWnd* member) which does member->SetParent(this). For everything that is supposedly "in" the groupbox, I call addMember. I have to do this since the draw order of MFC put all my buttons "under" the CBetterGroupbox background. It works fine. The controls are now drawn after CBetterGroupbox::OnPaint is done. However, now when I click a button, the handler in the main dialog is not called, probably since the message map now sends the ON_BN_CLICKED messages only to the CStatic level, not to CDialog level. How do I fix this? Is there any easy way to pass all the messages a class receives up to its parent? Desperately looking for help.

    R 1 Reply Last reply
    0
    • C crewchill

      Hi all. First, thanks for all the cool articles around. Really helpful. Second, I got a dumb question: I created a CStatic-derived class because I hate the normal groupbox MFC provided. Lets call it CBetterGroupbox. I put in CBetterGroupbox::addMember(CWnd* member) which does member->SetParent(this). For everything that is supposedly "in" the groupbox, I call addMember. I have to do this since the draw order of MFC put all my buttons "under" the CBetterGroupbox background. It works fine. The controls are now drawn after CBetterGroupbox::OnPaint is done. However, now when I click a button, the handler in the main dialog is not called, probably since the message map now sends the ON_BN_CLICKED messages only to the CStatic level, not to CDialog level. How do I fix this? Is there any easy way to pass all the messages a class receives up to its parent? Desperately looking for help.

      R Offline
      R Offline
      Ryan Binns
      wrote on last edited by
      #2

      You can do this overriding OnCommand() and send a WM_COMMAND messages to the parent in response, such as

      CBetterGroupbox::OnCommand(WPARAM wParam, LPARAM lParam)
      {
      CWnd *pParent = GetParent();
      ASSERT_VALID(pParent);
      pParent->SendMessage(WM_COMMAND, wParam, lParam);
      }

      This should take care of any control command messages, but it won't help with common controls that use WM_NOTIFY messages. However, a better way would be to call SetOwner() on the child windows to set their owner to the dialog box. This will cause all the control messages to be sent to the dialog box instead of the group box. I'm not sure if this works for common controls, though. I think it does, but perhaps you can test it :) Hope this helps Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
      Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups