?
Solved

NM_RCLICK Windows message - HELP.....

Posted on 1999-01-07
6
Medium Priority
?
390 Views
Last Modified: 2013-12-03
Hi,

I have a tree control and I need to let the client know when the user right clicks the mouse. I have handled the Windows Message NM_RCLICK. However I have a slight problem... When the user right clicks, the node does not stay selected... it reselects the node that was selected previously. What is causing this... How do I get it to actually select a node when the right mouse button is clicked...

please help me...

TIA

Emma
0
Comment
Question by:middlel
[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
  • 3
  • 2
6 Comments
 

Expert Comment

by:T38Jet
ID: 1418285
have you tried the myControl.SetFocus inside the MouseDown event?
0
 

Author Comment

by:middlel
ID: 1418286
Is that a VB method??? The C++ ones are asking you to pass in a handle to the window that will receive the focus... I just want a tree node to get selected.  What do you think?

regards

Emma

0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 240 total points
ID: 1418287
I've had this problem and it seems to be part of the standard tree control behaviour

I can't give you a very good explanation of why....there seems to be some wierd logic in the tree control...that there is more than one why of selecting an item....the whole behaviour depends on what happens before...

IIRC this is what happens :

If you right-click on an item that's not already selected, the selection appears to jump to a new item...however afterwards it jumps back.  The fact is the new item was never truly selected, I think if you use GetNextItem (MFC) or TVM_GETNEXTITEM (SDK) to find the selection, you will find the control thinks the old item is still selected.

So assuming you want the selection to stay on the new item, you need to explicitly set it...here's how

In response to NM_RCLICK
(a) Use GetMessagePos to get the cursor position when this message occured
(b) Use HitTest (MFC) or TVM_HITTESTINFO (SDK) to test which item in the tree this position corresponds to.
(c) Assuming you want the selection to stay on the new item after the option is completed, explicitly set the new selection to the item found by (b) [to my feeble mind this makes more sense than having the selection jump back to some other item].
(d) The item to perform whatever right click on is the item you got from (b)




0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:middlel
ID: 1418288
Thanks for the response... It was very useful... Can you take a look at the method... OnRClick();

It compiles, but nothing is found when it does a TreeView_HitTest();
Have I done something wrong when get the coordinates or is it a different problem completely...? If it is then I'll close the question and give the points to you...

Thanks

Emma

0
 

Author Comment

by:middlel
ID: 1418289
Adjusted points to 80
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1418290
Sorry I missed your follow up till now (too late ?)

GetMessagePos is in screen coordinates

HitTest is I think in window coordinates

Stick in the debugger or write to a log file.  If the coordinate systems are different use ScreenToClient to convert the mesage position to a client coords for the tree control
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

752 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