-
January 18th, 2009, 11:38 AM
#1
Teach Class Wizard recognizing custom event and creating automatically custom handler
I created a custom CWnd derived control, a BUTTON, like CButton but with extended custom functionalities.
Is there any way to let ClassWizard automatically handle the BN_CLICKED event like in a normal button control?
And is there any way to let ClassWizard automatically create handlers to events defined into the custom control, like BN_CLICKED? For example, let's say the button sends the BN_MOUSE_OVER event message, is it possible to teach ClassWizard in resource editor to show in the events of the control, the BN_MOUSE_OVER event, and to create the skeleton of the OnMouseOver function, all automatically like it does for BN_CLICKED events?
- Buzzyous -
-
January 18th, 2009, 12:06 PM
#2
Re: Teach Class Wizard recognizing custom event and creating automatically custom han
AFAIK, it's not possible to "teach" the Wizard doing that for a custom control, then no way... need a little sweat to map yourself the message handlers.
-
January 18th, 2009, 12:11 PM
#3
Re: Teach Class Wizard recognizing custom event and creating automatically custom han
Ok thank you.
Anyway, I sent from mu button custom control the message BN_CLICKED in the following way:
Code:
//In the control class, MyButton.
//When left mouse button is released, over the button, after it having been pressed:
GetParent()->SendMessage(BN_CLICKED);
//In the CDialog derived parent class, the message map:
BEGIN_MESSAGE_MAP(ButtonTryDialog, CDialog)
//{{AFX_MSG_MAP(ButtonTryDialog)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_CUSTOM2, OnButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
The OnButton only AfxMessageBoxes a text, "Pressed". It doesn't show... What I'm doing wrong?
- Buzzyous -
-
January 18th, 2009, 12:40 PM
#4
Re: Teach Class Wizard recognizing custom event and creating automatically custom han
BN_CLICKED is not a message itself, but a notification sent via WM_COMMAND message when the user clicks the control.
-
January 18th, 2009, 01:41 PM
#5
Re: Teach Class Wizard recognizing custom event and creating automatically custom han
Okay, it's clear now.
I sent WM_COMMAND, following the MSDN documentation indications, as follows:
Code:
GetParent()->SendMessage(WM_COMMAND,BN_CLICKED<<16 | GetDlgCtrlID(),(long)m_hWnd);
It works, even omitting the last m_hWnd parameter. This is technically correct, but is conceptually correct? Just to deeper understanding...
- Buzzyous -
-
January 19th, 2009, 08:33 AM
#6
Re: Teach Class Wizard recognizing custom event and creating automatically custom han
Technically it's correct, even LPARAM partameter of WM_COMMAND is NULL because a command can also be sent for a menu item or an accelerator (as for an example you can map the same command handler for a button control, for a menu item, and for an accelerator keystroke).
Conceptually, what you want to accomplish is not quite OK, because normally a notification (in our case BN_CLICKED) is expected in the parent window when the user does something (in our case, user clicks in a button).
-
January 19th, 2009, 04:33 PM
#7
Re: Teach Class Wizard recognizing custom event and creating automatically custom han
Yes, youìre right, but I send this message exactly when the left click is released from the custom button area, and if it was pressed there. So this message is sent when the user presses the button.
Thank you, couldn't rate 'cause already done too recentlu
- Buzzyous -
-
January 20th, 2009, 09:36 AM
#8
Re: Teach Class Wizard recognizing custom event and creating automatically custom han
Unfortunately, adding custom controls and handlers to class wizard disappeared around the time of Visual Studio 2003. However, the ability to create handlers is still possible if you are willing to craft your own member variable wizard. This is accomplished by writing a Visual Studio add-in. As an example, please refer to ClassWiz.
Gort...Klaatu, Barada Nikto!
-
January 20th, 2009, 11:06 AM
#9
Re: Teach Class Wizard recognizing custom event and creating automatically custom han
Originally Posted by Buzzyous
Okay, it's clear now.
I sent WM_COMMAND, following the MSDN documentation indications, as follows:
Code:
GetParent()->SendMessage(WM_COMMAND,BN_CLICKED<<16 | GetDlgCtrlID(),(long)m_hWnd);
It works, even omitting the last m_hWnd parameter. This is technically correct, but is conceptually correct? Just to deeper understanding...
That fact it sometimes worked for you does NOT mean it is correct.
Moreover, it is completely wrong for Win64 system where LPARAM is NOT the same as long and WPARAM is NOT the same as UINT (see Windows Data Types
The correct code should look like:
Code:
GetParent()->SendMessage(WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(), BN_CLICKED), (LPARAM)m_hWnd);
Victor Nijegorodov
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
|