Solved

NM_RCLICK Windows message - HELP.....

Posted on 1999-01-07
6
363 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
  • 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 80 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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 article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now