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,410 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 125 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 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