CButton OnRButtonDown
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 20

Thread: CButton OnRButtonDown

  1. #1
    Join Date
    Jun 2004
    Posts
    1,329

    CButton OnRButtonDown

    I want to have a help message come when the user Right Clicks a CButton Control. The message would be different for every implementation of the control, so I can't just subclass the control and override OnRightButtonDown member function.

    I probobly have to subclass a control with a virtual function for the right button, but I'm not sure if I have to have a virtual function. I need to be able to write the function at design time.

    Any suggestions?
    Rate this post if it helped you.

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,583

    Re: CButton OnRButtonDown

    Do the help messages you want to display for the various buttons differ not only in the message itself, but also in the way displaying the message is handled? If not, a simple CString member (or something similar) in the derived class could hold the message.

    If you are really going to use a virtual function, you will need a separate class for every single button. (They would then be derived from a single common base class that in turn is derived from CButton.)

    HTH

  3. #3
    Join Date
    Dec 2009
    Posts
    145

    Re: CButton OnRButtonDown

    How can that be such an insightful remind ?

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,216

    Re: CButton OnRButtonDown

    Quote Originally Posted by ADSOFT View Post
    The message would be different for every implementation of the control, so I can't just subclass the control and override OnRightButtonDown member function.
    Why not? Subclass the control, add a ON_COMMAND_RANGE handler, and use a std::map to map the control id to a CString. When your range handler gets called, do a lookup in the map to get the CString value.

  5. #5
    Join Date
    Jul 2009
    Posts
    37

    Re: CButton OnRButtonDown

    Quote Originally Posted by Eri523 View Post
    Do the help messages you want to display for the various buttons differ not only in the message itself, but also in the way displaying the message is handled? If not, a simple CString member (or something similar) in the derived class could hold the message.

    If you are really going to use a virtual function, you will need a separate class for every single button. (They would then be derived from a single common base class that in turn is derived from CButton.)

    HTH
    Is this CMap or std::map ?
    Oops, message mapping already is about map
    Left click to do, right click to help! sounds not right in usual format
    Nice nofifying message works better, you don't think so ? e.g mousehovre
    Sig-na-tju-(r)

  6. #6
    Join Date
    Jun 2004
    Posts
    1,329

    Re: CButton OnRButtonDown

    Excellent suggestions.

    I got something to work but I'm not too thrilled about it. I overode the PreTranslate member function of the diaglog box and Trapped the RightMouseButton and got the hwd(window handle of the control).

    I know that messing with PreTranslate is not good Framework programing., though.


    What about creating a function pointer?

    I can intialize it to NULL. After overriding the Right Button, it will excute the function if it's not NULL.

    I would like the function to be either global or a member function of a FORMVIEW or CDialog.

    Any suggestions?
    Rate this post if it helped you.

  7. #7
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,583

    Re: CButton OnRButtonDown

    Quote Originally Posted by ADSOFT View Post
    What about creating a function pointer?
    Well, from the semantic point of view, that wouldn't be too much a difference compared to a virtual function. In fact, virtual functions are internally implemented in terms of function pointers. But the function pointer approach would be more C-style, not really C++.

    I would like the function to be either global or a member function of a FORMVIEW or CDialog.
    I would suggest to try to avoid global functions as long as possible. I don't really know how member pointers to member functions are handled. I simply never had the need to even consider using something like that. Static member functions, however, would be handled much like global functions in that respect. (We already had a recent discussion about that, you remember? )

  8. #8
    Join Date
    Jun 2004
    Posts
    1,329

    Re: CButton OnRButtonDown

    Quote Originally Posted by Eri523 View Post
    Well, from the semantic point of view, that wouldn't be too much a difference compared to a virtual function. In fact, virtual functions are internally implemented in terms of function pointers. But the function pointer approach would be more C-style, not really C++.



    I would suggest to try to avoid global functions as long as possible. I don't really know how member pointers to member functions are handled. I simply never had the need to even consider using something like that. Static member functions, however, would be handled much like global functions in that respect. (We already had a recent discussion about that, you remember? )

    I created a CButton derived class with CString member functions and OverRode the OnRButtonDown function. Initalized the CStrings on OnInit of the Dialog. Worked Great!!

    I still want to toy with the Static Function pointer stuff. I believe that you can make a function pointer to a member function of a given Class as a member of the Class. In otherwords, I can create two member function pointers of my CButton Derived Class that would pointer to Member functions of CFormView and CDialog. I could set flags as to which to implement or just execute them as long as the function pointer don't point to NULL. ...Of course you are more than welcome to try it before me and let me know.

    How does Microsoft/MFC set it up that you are allowed to create a message handler for Bn_Clicked and DblBn_Clicked. We should be able to somehow do the same thing?
    Rate this post if it helped you.

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

    Re: CButton OnRButtonDown

    Did you consider handling WM_RBUTTONUP (or, perhaps, better, WM_CONTEXTMENU) rather than WM_RBUTTONDOWN?
    Victor Nijegorodov

  10. #10
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,957

    Re: CButton OnRButtonDown

    I still want to toy with the Static Function pointer stuff.
    Yeah, as far as I can tell this is your main point of interest now.

    But considering your original post, function pointers would spoil the OOP approach. This is how I would handle the situation:

    1. Right-clicked button becomes a source of event to help rendering object (HRO) encapsulating all the required details. At the same time the button becomes a context for the rendering.
    2. A button does nothing but notify HRO providing minimal context information (most probably ctrlID would be enough).
    3. HRO retrieves all the details corresponding to the context and renders the visual element (balloon for example) in accordance with the details and the context. (This way for example, the source control becomes a parent window for the rendered visual element.)
    4. End of story. No place for function pointers though, sorry...
    Best regards,
    Igor

  11. #11
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,216

    Re: CButton OnRButtonDown

    Or you could implement context help (help that uses the '?' icon that the user drags onto a control).

  12. #12
    Join Date
    Jun 2004
    Posts
    1,329

    Re: CButton OnRButtonDown

    Quote Originally Posted by VictorN View Post
    Did you consider handling WM_RBUTTONUP (or, perhaps, better, WM_CONTEXTMENU) rather than WM_RBUTTONDOWN?
    Yep, but you still have to subclass the Control. I was originally looking for a way to work with CButton and not to subclass the control.

    Now, that I accepted that I have to subclass the control (unless you know of a way to overide OnRButtDown without subclassing).


    At this point I'm looking for a way to add functionality to my Button Class at design time without haveing to modify the Derived class. All I can think of is a function pointer or a pointer to function of the class type I'm working with?
    Rate this post if it helped you.

  13. #13
    Join Date
    Jun 2004
    Posts
    1,329

    Re: CButton OnRButtonDown

    Quote Originally Posted by Arjay View Post
    Or you could implement context help (help that uses the '?' icon that the user drags onto a control).
    Isn't the Context Help only for the the Dialog Class(or the parent of the CButton).
    Rate this post if it helped you.

  14. #14
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,216

    Re: CButton OnRButtonDown

    Quote Originally Posted by ADSOFT View Post
    Isn't the Context Help only for the the Dialog Class(or the parent of the CButton).
    What's your goal? Is it to generate help text for a control? If so, that's what context help is for. It's implemented on the parent window (dialog, etc) that contains controls. It's not implemented for each control (unless the control is a container of other controls).

  15. #15
    Join Date
    Jun 2004
    Posts
    1,329

    Re: CButton OnRButtonDown

    Quote Originally Posted by Arjay View Post
    What's your goal? Is it to generate help text for a control? If so, that's what context help is for. It's implemented on the parent window (dialog, etc) that contains controls. It's not implemented for each control (unless the control is a container of other controls).
    Sound like it should work:
    afx_msg void OnContextMenu( CWnd* pWnd, CPoint pos );

    Parameters
    pWnd Handle to the window in which the user right clicked the mouse. This can be a child window of the window receiving the message. For more information about processing this message, see the Remarks section.
    pos Position of the cursor, in screen coordinates, at the time of the mouse click.

    pWnd is a pointer to a window, not a handle????


    I read some of the examples and they usually just pop up a menu when the right button is clicked. I haven't seen on where you right click a control. The example leads you to believe that is mostly for the parent window.

    I'm goint to try it on a tree control, lets see what happens.
    Rate this post if it helped you.

Page 1 of 2 12 LastLast

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