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?
Re: How to handle WM_SHOWWINDOW in a base class
Please, post message maps code of your base class and subclasses.
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?
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.
Re: How to handle WM_SHOWWINDOW in a base class
Quote:
Originally Posted by
DeepT
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.
Re: How to handle WM_SHOWWINDOW in a base class