CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2004
    Posts
    1,361

    How to handle WM_SHOWWINDOW in a base class

    The class hierarchy is CDialog -> BaseClass -> SubClass. BaseClass is abstract. Whenever an instance of SubClass is shown I want my BaseClass to capture the event and do something. This is the WM_SHOWWINDOW message.

    I have the message handler registered in my base class, but not in my subclass. I figured the subclass would get the message, but not have a handler for it, so the base class method would take over and handle the message, but this doesn't seem to be happening. I could just capture the event in each subclass and then have it do BaseClass::OnShowWindow(), but that seems a little clunky to be doing that for each type of subclass. Also anytime someone forgot to add that to the subclass, it would break that mechanism. There has to be a better way. Any ideas?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to handle WM_SHOWWINDOW in a base class

    Please, post message maps code of your base class and subclasses.
    Victor Nijegorodov

  3. #3
    Join Date
    Sep 2004
    Posts
    1,361

    Re: How to handle WM_SHOWWINDOW in a base class

    You mean this?
    Base Class:
    Code:
    BEGIN_MESSAGE_MAP(CBubbleBaseDlg, CDialog)
    	ON_WM_TIMER()
    	ON_WM_SHOWWINDOW()
    END_MESSAGE_MAP()
    Subclass:
    Code:
    BEGIN_MESSAGE_MAP(CVista7BubbleDlg, CDialog)
    	ON_BN_CLICKED(IDC_BUTTON_BUBBLE, &CVista7BubbleDlg::OnBnClickedButtonBubble)
    	ON_WM_SHOWWINDOW()
    	ON_WM_TIMER()
    END_MESSAGE_MAP()
    Originally I didn't want to have the last two messages in the sub class. Now that I posted it, is the fact that I have CDialog in the subclass message map the problem? If it was CBubbleBaseDlg, and I didn't have the ON_WM ShowWindow / timer then it would have worked?

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: How to handle WM_SHOWWINDOW in a base class

    Probably. Take the handlers out of your derived class and get the hierarchy right in the message map and see what happens.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to handle WM_SHOWWINDOW in a base class

    Quote Originally Posted by DeepT View Post
    You mean this?
    Base Class:
    Code:
    BEGIN_MESSAGE_MAP(CBubbleBaseDlg, CDialog)
    	ON_WM_TIMER()
    	ON_WM_SHOWWINDOW()
    END_MESSAGE_MAP()
    Subclass:
    Code:
    BEGIN_MESSAGE_MAP(CVista7BubbleDlg, CDialog)
    	ON_BN_CLICKED(IDC_BUTTON_BUBBLE, &CVista7BubbleDlg::OnBnClickedButtonBubble)
    	ON_WM_SHOWWINDOW()
    	ON_WM_TIMER()
    END_MESSAGE_MAP()
    If CBubbleBaseDlg is the base class for CVista7BubbleDlg try to change the CVista7BubbleDlg message map to be:
    Code:
    BEGIN_MESSAGE_MAP(CVista7BubbleDlg, CBubbleBaseDlg)
    	ON_BN_CLICKED(IDC_BUTTON_BUBBLE, &CVista7BubbleDlg::OnBnClickedButtonBubble)
    END_MESSAGE_MAP()
    then only the base class handlers for WM_TIMER and WM_SHOWWINDOW will be used.
    Victor Nijegorodov

  6. #6
    Join Date
    Sep 2004
    Posts
    1,361

    Re: How to handle WM_SHOWWINDOW in a base class

    Thanks, that worked.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured