LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get Mouse Cursor

Solved!
Go to solution

Is there a way to get the current mouse cursor?  I know there is a function for changing it, but I want to know what it currently is.  

 

The reason for this is because I have a multicolumn listbox.  And on Mouse Up I have code that detects what column you clicked on and sort on that column.  But I also allow for adjusting the column width.  The problem is if you adjust the width this is also registered as a Mouse Up and will sort the column, when the user didn't want to do that.  

 

My simple solution was to look at the current mouse cursor, and if it was the one that is used for adjusting the column size, on the Mouse Up, then just ignore the event.  Any thoughts?  Thanks.

0 Kudos
Message 1 of 22
(6,517 Views)

Presumably the Point to Row Col only gives you the row-col cluster, but you can add up the column widths to figure out if the click was on a border.


___________________
Try to take over the world!
Message 2 of 22
(6,502 Views)

Well I don't like this solution because of the extra code, and edge cases associated with it.  The Point to Row returns if you are in bounds, the row and column, and if you are in the symbol.  If I am in the first column header it reutrns row -1 column 0, if I have my cursor on the separator (and my mouse has the separator icon) it still returns -1 0.  So this function doesn't return to me any more information other than the cell I'm in.

 

I could use this to then say get the position and size of the cell, then see if my mouse is in that space, minus a few pixels.  That is this code

 

Column Separator Test_BD.png

 

One problem I have with this is I don't know if the MCLB has moveable column separators turn on or not.  Seems that property isn't exposed, and after a quick search I find this thread...made my me where I was complaining about this missing feature.  Why am I forced to continually rediscover LabVIEW limitations?

 

http://forums.ni.com/t5/LabVIEW/Moveable-Column-Seperators-Property/td-p/2217334

 

Since I am eventually making this into an XControl, I can add my own Allow Moveable Separators property, where if false it will set the mouse cursor back, and discard mouse downs on the separator, then use the code above to determine where the mouse click was.  I guess this is better than trying to read the cursor image, but I did find this in that thread which shows a way to do that, it just doesn't work, but does try to answer the original question.  I'll play around with it and see if I can get it to work.

 

https://decibel.ni.com/content/docs/DOC-15261

0 Kudos
Message 3 of 22
(6,489 Views)

@Hooovahh wrote:

 

 and after a quick search I find this thread...made my me where I was complaining about this missing feature.

 

http://forums.ni.com/t5/LabVIEW/Moveable-Column-Seperators-Property/td-p/2217334



Well, at least I'm consistent...


___________________
Try to take over the world!
0 Kudos
Message 4 of 22
(6,485 Views)

It looks like in windows for me my cursor starts at icon=1. I don't know if this is the default cursor when hovering a listbox though. If it is, you can set the cursor to icon 1, then set it back, and compare the cursor IDs. If they are the same, then you must have already been using the default cursor.

 

change cursor.png

0 Kudos
Message 5 of 22
(6,471 Views)

Nevermind, I tested with a listbox and it seems like it's always set to icon=0 even when resizing 😞

0 Kudos
Message 6 of 22
(6,465 Views)
Solution
Accepted by topic author Hooovahh

Have you tried the Get Clicked Column Header method for MCLB?  It returns a -2 when resizing the column headers

Capture.PNG

aputman
Message 7 of 22
(6,461 Views)

@aputman wrote:

Have you tried the Get Clicked Column Header method for MCLB?  It returns a -2 when resizing the column headers


Man, why did you have to go and make it all simple?  I tested several things and I'm still going to post them for completeness but I found two other, inferior ways of doing this task.  Still useful information in those methods, just not as good for this one case.

 

I found two ways to get the icon of the cursor.  One is using the .Net method linked to earlier.  The code could use some work and there was some functions being repeated twice but it got an image of the cursor along with a few other things.  I also found an AutoIt3 function that returns the selected cursor so I turned that into an EXE and embedded it in the VI.  I then wrote code to speed test these two methods and the one shown earlier.  The result was that the AutoIt version was the slowest at around 30ms, .Net was and LabVIEW native was about the same at 20ms or less.  But none of that really matters unless you want to know the cursor image which in my case I did, because I didn't know there was an easier way to know if the header was clicked.  In any case the code is posted showing how to get the mouse cursor as an image, or as text using these methods.  Thanks everyone.

0 Kudos
Message 8 of 22
(6,451 Views)

My bad.  Smiley Very Happy

aputman
0 Kudos
Message 9 of 22
(6,439 Views)

GRRRRAHHHH...turns out this invoke node doesn't work right when in an XControl...which was the goal of all of this.  I need to do some more testing but it appears this function always returns a -2 when in an XControl.  If I can make a simple example I'll make a new thread.

 

Edit: it must be something else I'm doing the simple test works.

0 Kudos
Message 10 of 22
(6,434 Views)