Solved

How do I get a right mouse click in a list box to generate a LBN_SELCHANGE message.

Posted on 2011-02-17
5
1,405 Views
Last Modified: 2013-11-20
I have created a CListBox-derived class and therein I re-implement the OnRButtonDown event handler.

In response to the right button click, I change the current selection in the list box using the SetCurSel function.

After the current selection has been changed, I want to generate a LBN_SELCHANGE message so that the dialog class in which the list box is located knows that the current selection has changed and reacts accordingly.

It is this last step that has me stumped.
0
Comment
Question by:srhdavidson
5 Comments
 
LVL 3

Expert Comment

by:imaki06
Comment Utility
You should send the LBN_SELCHANGE with the PostMessage command.

myDlg->PostMessage(LBN_SELCHANGE, wpar, lpar);

You can check the parameter values from:
LBN_SELCHANGE
0
 
LVL 11

Expert Comment

by:DeepuAbrahamK
Comment Utility

I would suggest to use Posting or sending a user-defined message to the main thread is the best way to trigger something in the main thread from other threads.
WM_APP is a windows constant that is higher than any message used by windows,

    #define MY_WM_MESSAGE1  (WM_APP + 1)


    ::PostMessage(hwnd, MY_WM_MESSAGE1, (WPARAM)0, (LPARAM)0);
  or,
    ::SendMessage(hwnd, MY_WM_MESSAGE1, (WPARAM)0, (LPARAM)0);

  In the header file you could add:

    afx_msg LRESULT OnMyMessage1(UINT wParam, LONG lParam);


        //}}AFX_MSG_MAP
        ON_MESSAGE(MY_WM_MESSAGE1, OnMyMessage1)
    END_MESSAGE_MAP()


      To handle the user defined message:

    LRESULT CMainFrame::OnMyMessage1(UINT wParam, LONG lParam)
    {
        ...
      }
0
 
LVL 30

Accepted Solution

by:
Zoppo earned 125 total points
Comment Utility
I don't think sending a LBN_SELCHANGE message directly works since it's a notification message.

From MSDN http://msdn.microsoft.com/en-us/library/bb775161%28v=vs.85%29.aspx you can see that is sent to the parent with a WM_COMMAND message.

So, within a function from your derived CListBox class you should be able to send it like this:

GetParent()->PostMessage( WM_COMMAND,MAKEWPARAM( GetDlgCtrlID(), LBN_SELCHANGE ), (LPARAM)GetSafeHwnd() );

Hope that helps,

ZOPPO
0
 

Author Closing Comment

by:srhdavidson
Comment Utility
Zoppo's solution provided exactly what I needed. Thank you!
0
 
LVL 30

Expert Comment

by:Zoppo
Comment Utility
You're welcome - I'm glad I could help ...

Have a nice weekend,

best regards,

ZOPPO
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now