?
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
Medium Priority
?
1,411 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Expert Comment

by:imaki06
ID: 34923560
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
ID: 34924762

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 31

Accepted Solution

by:
Zoppo earned 500 total points
ID: 34925006
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
ID: 34925867
Zoppo's solution provided exactly what I needed. Thank you!
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 34925891
You're welcome - I'm glad I could help ...

Have a nice weekend,

best regards,

ZOPPO
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

770 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