LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Show/Hide Panel control when mouse is Over.

Assume : C1 is Numeric control & C2 is a Decoration Control.

how can I Show C1 when mouse over C2 and Hide C1 When mouse Leave C2 ?
0 Kudos
Message 1 of 7
(4,913 Views)
You would need to use Extended Mouse Events. CVI doesn't, by default send Mouse Move events to the callbacks. You would need Mouse Move events to accomplish this. When you receive a mouse move event over C2 you would set C1 to visible. Then, monitor the cursor and when it leaves the area of C2, hide C1 back.

The extended Mouse event functions can be found in the Programmer's Toolbox (cvi\toolslib\toolbox\toolbox.fp) under User Interface Utilities->Extended Mouse Events.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 7
(4,913 Views)
I used your idea, but i get EVENT_MOUSE_MOVE all time that i move mouse, not only when it over the control.
0 Kudos
Message 3 of 7
(4,913 Views)
Oops, yes, sorry I forgot how the behavior worked. Windows messaging is based on window, and in CVI there are not separate windows for each control. Therefore, you install entended events to designate which control callback will get the Mouse move events, but it will get them for the entire panel. So, you need to setup a check for when the mouse moves over the control, then when it does hide the control until the mouse moves move off the control.

Your code would look something like this (where eventData1 and eventData2 hold the current mouse position). This example would change the text of the button PANEL_GO to green when the mouse was over it.

case EVENT_MOUSE_MOVE:
if(isOver)
{
if((ctrlLeft >= eventData2) || (eventDa
ta2 > (ctrlLeft+ctrlWidth)))
{
if((ctrlTop > eventData1) || (eventData1 >= (ctrlTop+ctrlHeight)))
{
SetCtrlAttribute (panelHandle, PANEL_GO, ATTR_LABEL_COLOR,VAL_BLACK);
isOver = 0;
}
}
}
else
{
if((ctrlLeft <= eventData2) && (eventData2 < (ctrlLeft+ctrlWidth)))
{
if((ctrlTop < eventData1) && (eventData1 <= (ctrlTop+ctrlHeight)))
{
SetCtrlAttribute (panelHandle, PANEL_GO, ATTR_LABEL_COLOR, VAL_GREEN);
isOver = 1;
}
}
}

Best Regards,

Chris Matthews
National Instruments
Message 4 of 7
(4,913 Views)
The tooltip instrument driver for CVI contains code for doing a similar thing
i.e. to display a context-sensitive text message when the mouse cursor hovers
over a control. This could be adapted to do what you want. See
http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/dfd062d0bcdebc
1786256a48005fd4b3?OpenDocument

However, the tooltip code works by installing a timer that periodically calls
GetRelativeMouseState() to get the current mouse coordinates and compares them
to the panel region assigned to each control and does a table look-up to find
out what control-specific text to display for a control. This raises an
interesting question: Wouldn't it be more efficient for the tooltip driver to
capture extended mouse events as Chris just described instead of using a timer
callback and mouse state-polling to accomplish the same thing? Or is this simply
a case of, "There's more than one way to skin a mouse"?

Nick J.

"Chris Matthews" wrote in message
news:506500000005000000FBAB0000-1031838699000@exchange.ni.com...
> Oops, yes, sorry I forgot how the behavior worked. Windows messaging
> is based on window, and in CVI there are not separate windows for each
> control. Therefore, you install entended events to designate which
> control callback will get the Mouse move events, but it will get them
> for the entire panel. So, you need to setup a check for when the
> mouse moves over the control, then when it does hide the control until
> the mouse moves move off the control.
>
> Your code would look something like this (where eventData1 and
> eventData2 hold the current mouse position). This example would
> change the text of the button PANEL_GO to green when the mouse was
> over it.
>
> case EVENT_MOUSE_MOVE:
> if(isOver)
> {
> if((ctrlLeft >= eventData2) || (eventData2 >
> (ctrlLeft+ctrlWidth)))
> {
> if((ctrlTop > eventData1) || (eventData1 >=
> (ctrlTop+ctrlHeight)))
> {
> SetCtrlAttribute (panelHandle, PANEL_GO,
> ATTR_LABEL_COLOR,VAL_BLACK);
> isOver = 0;
> }
> }
> }
> else
> {
> if((ctrlLeft <= eventData2) && (eventData2 <
> (ctrlLeft+ctrlWidth)))
> {
> if((ctrlTop < eventData1) && (eventData1 <=
> (ctrlTop+ctrlHeight)))
> {
> SetCtrlAttribute (panelHandle, PANEL_GO, ATTR_LABEL_COLOR,
> VAL_GREEN);
> isOver = 1;
> }
> }
> }
>
> Best Regards,
>
> Chris Matthews
> National Instruments
0 Kudos
Message 5 of 7
(4,913 Views)
O.K. So by this method i can check if mouse moves over rectangle region of control, but what can i do if i have control that is not rectangle, for example Gauge?
0 Kudos
Message 6 of 7
(4,913 Views)
Just do the math: rather than check to see if it's within a rectangle, check if it's in a circle. You'll need to know the circle center and radius. Then use Pythagorean's Principle to calculate the distance from the gauge center to the mouse.

See the attached project.
0 Kudos
Message 7 of 7
(4,913 Views)