Solved

NM_RCLICK Windows message - HELP.....

Posted on 1999-01-07
6
374 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C#: need to import an entire CSV file 4 59
How can i Install a new Data Source on Visual Studio 2 107
Is COM supported from Apache 1 66
Trouble with References... 5 60
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

828 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