[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
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,412 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:Deepu Abraham
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

650 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