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,409 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
MS Visual Studio 2015 - Install Error 5 106
Problem to open Excel file 15 263
Access to class from any project within a solution. 6 46
send messages to whatsapp programatically 2 115
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

734 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