CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2010
    Posts
    4

    How to make CComboBox response to WM_RBUTTONDOWN message?

    I have a dialog based application with one CComboBox control defined. How can I use right mouse click to cancel the drop down list? I tried to subclass CComboBox and overload WindowProc(), it doesn't work. The comboBox control can only receive WM_RBUTTONDOWN message when the drop down list is hiding.
    Left mouse click without selecting any item will cancel the list though.

    Thanks for any help.

  2. #2
    Join Date
    May 2000
    Location
    Armenia
    Posts
    201

    Re: How to make CComboBox response to WM_RBUTTONDOWN message?

    As the name implies combo box is a "combination" of edit box and list box.
    So when drop down list is shown list box is activated, when it is closed edit box is activated.
    To get the window handle of correspondent part of combo box you can use GetComboBoxInfo function which returns COMBOBOXINFO structure with hwndCombo (combo box window), hwndItem (edit box window) and hwndList (drop down list window).

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

    Re: How to make CComboBox response to WM_RBUTTONDOWN message?

    What exactly are you trying to accomplish?
    Gort...Klaatu, Barada Nikto!

  4. #4
    Join Date
    Jan 2010
    Posts
    4

    Re: How to make CComboBox response to WM_RBUTTONDOWN message?

    Thanks Armen for the hints, I will try to see if it works.

    What I want to accomplish, let me give an example. You are using Microsoft office 2007, or visual studio 2008, you have a dropdown list opened from a combobox, like selecting fonts, now when
    you Right Click in your editing area, the dropdown list will be collapsed without selecting
    anything, and a right click menu shown up in editing area.
    If the combobox is in default MFC style, right click in editing area will have no response at all,
    the dropdown list will stay there, and no right click menu will show.

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

    Re: How to make CComboBox response to WM_RBUTTONDOWN message?

    Be careful when changing the standard behavior of controls. How is the user supposed to know that they can right click on the control when the list is exposed? What is the purpose of the menu? Perhaps there is a better design for what you are attempting?
    Gort...Klaatu, Barada Nikto!

  6. #6
    Join Date
    Jan 2010
    Posts
    4

    Re: How to make CComboBox response to WM_RBUTTONDOWN message?

    I understand your point, somehow I got this requirement which contradict to the default behavior of the Control.
    However, for all the business applications such as MS Office, Visual Studio etc, the behavior is
    that, right click mouse will cancel the dropdown list of any combobox. I would appreciate if
    anyone has done this before or know a custom combobox control that works this way.

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to make CComboBox response to WM_RBUTTONDOWN message?

    Try to handle WM_CONTEXTMENU message and call ShowDropDown(FALSE) (if CComboBox::GetDroppedState returned TRUE)
    Victor Nijegorodov

  8. #8
    Join Date
    Jan 2010
    Posts
    4

    Re: How to make CComboBox response to WM_RBUTTONDOWN message?

    Add handler for WM_CONTEXTMENU doesn't help, I think it is because the ListBox part of ComboBox doesn't respond to RButtonDown message. Tried to subclassing Listbox but no luck yet.

  9. #9
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to make CComboBox response to WM_RBUTTONDOWN message?

    Quote Originally Posted by Brigadoon View Post
    I understand your point, somehow I got this requirement which contradict to the default behavior of the Control.
    However, for all the business applications such as MS Office, Visual Studio etc, the behavior is
    that, right click mouse will cancel the dropdown list of any combobox. I would appreciate if
    anyone has done this before or know a custom combobox control that works this way.
    The MFC CComboBox has this behavior because it's simply a wrapper to the underlying Windows control.

    MS Office, Visual Studio, etc have their own custom controls (which aren't necessarily based on the OS Windows controls).

    That being said, you may check out the MFC feature pack that is available on 2008 as it may emulate the new Office styled controls.

    If this isn't an option, I would go back to the author of the spec/requirements and explain that getting identical Office behavior isn't trivial.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured