LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to set the stateof a command button

I want to call a function when the user presses a command button (left click), then wait until he releases the mouse button, then call a second function.
Here is the code for EVENT_LEFT_CLICK:

CallFunction_1(...)
GetRelativeMouseState(panel, control, 0, 0, &mouseLButton, 0, 0);
while(mouseLButton)
{
ProcessSystemEvents();
ProcessDrawEvents ();
GetRelativeMouseState(panel, control, 0, 0, &mouseLButton, 0, 0);
}
CallFunction_2(...)

My Problem is, that the button does not chage its state to "pressed", so it appears to the user that he has not clicked on it.
Is there any possibility to set the command button th the pressed state?
0 Kudos
Message 1 of 3
(3,025 Views)
The reason for this is that the LEFT_CLICK event has not been processed yet. We allow you to "swallow" any event to basically eliminate the built in effect of that event. In your case you want the normal effect of the LEFT_CLICK event to occur (button appears pressed on the panel), but you also want to launch a loop to check when the mouse has been released. This is easily done through posting a deferred call. A deferred call allows the current event to be completed and then calls the deferred callback after that. So your code would be changed to:

In LEFT_CLICK,

CallFunction_1(...)
PostDeferredCall (funcName, (void*)control);

Then write a function "funcName" with prototype:

void CVICALLBACK funcName (void *callbackData);

and code:

void CVICALLBACK fu
ncName (void *callbackData)
{
int control = (int)callbackData;
int mouseLButton = 0;

GetRelativeMouseState (panel, control, 0, 0,
&mouseLButton, 0, 0);
while(mouseLButton)
{
ProcessSystemEvents();
ProcessDrawEvents ();
GetRelativeMouseState (panel, control, 0, 0,
&mouseLButton, 0, 0);
}
CallFunction_2(...)
}

This should solve your problem.

Best Regards,

Chris Matthews
Measurement Studio Support Manager
Message 2 of 3
(3,025 Views)
Hi surich,

Before entering your while loop, set the control value to 1.
You may want to set and reset the command button color as well.

GetCtrlAttribute (panel, control, ATTR_CMD_BUTTON_COLOR,
&originalColor);
SetCtrlVal (panel, control, 1);
SetCtrlAttribute (panel, control, ATTR_CMD_BUTTON_COLOR, VAL_DK_GRAY);

while (mouseLButton)
{
...
}

GetCtrlAttribute (panel, control, ATTR_CMD_BUTTON_COLOR,
&originalColor);


Regards,

//----------------------------------------------------------
Reed Blake
Beta Technology
Industrial and Scientific Computing


surich wrote in message
<101-50650000000800000061150000-982303670000@quiq.com>...
>I want to call a function when the user presses a command button (left
>click), then wait until he releases
the mouse button, then call a
>second function.



>My Problem is, that the button does not chage its state to "pressed",
>so it appears to the user that he has not clicked on it.
>Is there any possibility to set the command button th the pressed
>state?
0 Kudos
Message 3 of 3
(3,025 Views)