LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Odd behaviour of SetInputMode

In the help for SetInputMode () function you can read (highlight is mine):

panelOrMenuBarHandle int Handle of the panel or menu bar on which you want to set the recognition of user input.

Use –1 to specify all panels and all menubars.
controlOrMenuItemID int ID of the control or menu item on which you want to set the recognition of user input.

The ID is the defined constant you assign to the control or menu item in the User Interface Editor or the ID that you obtain from NewCtrl or NewMenuItem.

Use –1 to specify all controls on the panel or all items in the menu bar.

 

That -1 value is consistent with other functions that use this special value to include all elements in a group, I noted however that passing 0 has the same effect of passing -1 either parameter. It seems a bug to me since no element of a UIR can have an ID of 0. This is particularly annoying when you have a function that programmatically calls SetInputMode: if some of the parameters is 0 the operator ends up with the user interface partly or fully grayed out! Smiley Surprised

 

I know that this should not happen but the function should protect itself against wrong parameters. At present I resolved by creating the following wrapper function:

//--------------------------------------------------------------------------
//
// Function DimUndimCtrl
//
//--------------------------------------------------------------------------
/// HIFN DimUndimCtrl ()
/// HIFN Calls SetInputMode only if 'panel' and 'control' are valid (not null)
/// HIFN Same parameters of SetInputMode ()
void DimUndimCtrl (int panel, int control, int status)
{
	if (panel != 0 && control != 0) SetInputMode (panel, control, status);

	return;
}

 

It seems to me that this bug is to be corrected (better) or at least the online help is to be updated to follow actual function behaviour (worse).



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 1 of 3
(3,895 Views)

You didn't try SetInputMode ( -2, -2, 0 ); Smiley Wink It seems that the function only checks for values less than 1...

0 Kudos
Message 2 of 3
(3,892 Views)

Yes, you are correct. It looks as if the function is treating all negative values (plus zero!) equally

 

I don't know what the reason for this is, and I agree that this is a bit unintuitive, but whatever that reason was, the behavior cannot be changed now, since the risk of breaking existing programs that might be relying on this behavior is too high. Especially since, from a very narrowly legalistic perspective, it doesn't really contradict the documentation, since it is true that if you pass -1 you get the behavior that it says you do Smiley Tongue

 

But, of course, the documentation is misleading, and it can and should be changed.

 

Luis

0 Kudos
Message 3 of 3
(3,695 Views)