?
Solved

NM_RCLICK Windows message - HELP.....

Posted on 1999-01-07
6
Medium Priority
?
412 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 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

850 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