-
June 26th, 2012, 09:43 AM
#1
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?
-
June 26th, 2012, 12:41 PM
#2
Re: How to handle WM_SHOWWINDOW in a base class
Please, post message maps code of your base class and subclasses.
Victor Nijegorodov
-
June 26th, 2012, 02:33 PM
#3
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?
-
June 26th, 2012, 02:37 PM
#4
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.
-
June 26th, 2012, 02:52 PM
#5
Re: How to handle WM_SHOWWINDOW in a base class
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.
Victor Nijegorodov
-
June 26th, 2012, 02:52 PM
#6
Re: How to handle WM_SHOWWINDOW in a base class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|