Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Possible Bug in MS6.0

I think I found a bug when working with the MS6.0 NiButton control under VC++ 6.0. I'm running win2000 if that matters. Anyway, if you do the following you'll see what I'm talking about:

a.) Drag a CNiButton control off of you tool bar and onto your dialog.
b.) Change the style to command button or toggle button.
c.) Set it to 'Switch until released'.
d.) Double click it and put AfxMessageBox("hello"); as the only line of code.
e.) Run the program.

When you click on the button you get hello on the screen. If you come back at any time and move the pointer over the control so that it comes into focus you get hello on the screen again. How come? Is it supposed to run twice? I use command buttons for everything, basically, and I don't
want things running twice, especially without me knowing it. If I use a toggle button instead of a command button and set it to 'Switch until relased' it behaves similarly. If you change to 'Switch when pressed' then it actually says hello when you click on it but the button stays on until you click it again which prints hello on the screen and turns the button off again.

I thought that the difference between 'Switch until released' and 'Switch when pressed' is similar to the CVI idea of either a toggle button or a command button. In CVI command buttons have one state and toggles have two. That seems to make sense. Why do I want a command button with two states?

One work around is to handle the 'Click' event on these buttons rather then the 'Value Changed' event. This runs the routine once which seems to be the desired result. However I like to be able to double click on my dialog buttons and go to the code and you can't do that unless you use the default routine which h
andles the 'ValueChanged' event.


Hope I'm not just wasting your time. Please let me know if I'm doing something wrong.

Thanks,

Grant
Grant M. Johnson
Project Engineer
LECO Corporation
0 Kudos
Message 1 of 3
(3,365 Views)
The cause of this is that the value changes twice. Once when you press the button and one when you release the button. However, since you are bringing up a modal dialog on the mouse down value change, the second value change can't occur since there is never a mouse up event. The second value changed is in "limbo" until the button gets it's next mouse over event. I agree this is not ideal behavior and we will take a look at what can be done to make it behave better.

However, as you found out, the solution for this is to use the Click event. Even if we fixed this behavior, you most likely do NOT want two events for every left click which you will get for value changed on a command button.

We have ValueChanged as the default event because of al
l of the different toggle styles (LED, switch, toggle buttons) that would normally use this event defaultly. For command buttons though, the default event should be Click as with the native MFC command buttons.

Best Regards,

Chris Matthews
National Instruments
Message 2 of 3
(3,365 Views)
Sounds good Chris. Thanks.
Grant M. Johnson
Project Engineer
LECO Corporation
0 Kudos
Message 3 of 3
(3,365 Views)