Teach Class Wizard recognizing custom event and creating automatically custom handler
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Teach Class Wizard recognizing custom event and creating automatically custom handler

  1. #1
    Join Date
    Jan 2007
    Location
    Italy
    Posts
    156

    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 -

  2. #2
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    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.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  3. #3
    Join Date
    Jan 2007
    Location
    Italy
    Posts
    156

    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 -

  4. #4
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    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.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  5. #5
    Join Date
    Jan 2007
    Location
    Italy
    Posts
    156

    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 -

  6. #6
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    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).
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  7. #7
    Join Date
    Jan 2007
    Location
    Italy
    Posts
    156

    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 -

  8. #8
    Join Date
    Apr 1999
    Posts
    3,585

    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!

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,353

    Re: Teach Class Wizard recognizing custom event and creating automatically custom han

    Quote Originally Posted by Buzzyous View Post
    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center