LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Update increment (ATTR_INCR_VALUE) of a numeric control while holding mouse key pressed

Solved!
Go to solution

Hallo,

 

here's a problem with a numeric control.

I have a control wich accepts a pretty large range of values: 0.01 to 60000.

What I want to do is changing of its incremental value in dependence on the current range.

 

So, if the control value is 2000..6000 to change it in step of 1000, if it's below 2000 but above 200 - in step of 100 etc.

 

The following code works if I change the value of the control with SINGLE mouse-clicks. But if I just press the left mouse key and hold it, it doesn't work!

 

Debugging shows, that it treats events correctly and passes the attribute to the control (also correctly). But changing of ATTR_INCR_VALUE seems to have no influence until I release the mouse key.

 

------------------------------------

int CVICALLBACK SetTint (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
   float dIncValue=10.0, dIncValue_temp;

   switch (event)
   {
          case EVENT_VAL_CHANGED:
           GetCtrlVal(hMainPanel, MAINP_INTTIME, &fTint);
           if (fTint>2000.0) dIncValue=1000.0;
           if ((fTint<=2000.0)&&(fTint>100.0)) dIncValue=100.0;
           if ((fTint<=200.0)&&(fTint>20.0)) dIncValue=10.0;
           if ((fTint<=20.0)&&(fTint>=2.0)) dIncValue=1.0;
           if ((fTint<2.0)&&(fTint>0.2)) dIncValue=0.1;
           if (fTint<=0.2) dIncValue=0.01;
          

           SetCtrlAttribute (hMainPanel, MAINP_INTTIME, ATTR_INCR_VALUE, dIncValue);
           break............

-------------------------------------

 

Adding events like

          case EVENT_COMMIT:
          case EVENT_LEFT_CLICK:
          case EVENT_VAL_CHANGED:
          GetCtrlVal(hMainPanel, MAINP_INTTIME, &fTint);...

doesn't help.

 

Swallowing events after setting of the attribute like

          SetCtrlAttribute (hMainPanel, MAINP_INTTIME, ATTR_INCR_VALUE, dIncValue);
          return 1;

doesn't help.

 


This stuff -

        ProcessDrawEvents();
        ProcessSystemEvents();

doesn't help also.

 

Any other suggestions? 😕

0 Kudos
Message 1 of 12
(6,196 Views)

Hi Loevenson,

 

actually there is no solution for this issue, but we can look for a workaround. In the actual implementation, this feature is not implemented because of performance reasons. Continuously updating this value would decrease execution time. Do you want the Increment attribute to be updated and reflected in the control each time the EVENT_VAL_CHANGED event is called? Or are you just looking to have the value of the control increase faster at higher values?

 

 

Best Regards, Fabian

 

 

0 Kudos
Message 2 of 12
(6,060 Views)

I remember doing that very thing this way: I wouldn't use the INC property of the control but my own. So when VAL_CHANGED is received, I take the _previous_ value of the control, add my own INC, update the value displayed in the control. Also set my own INC to some log of the value, with proper truncation. This way I can have powers of 2, 10, Preferred Numbers, etc. At least that's how I remember it, it's been a few years.

0 Kudos
Message 3 of 12
(6,056 Views)

I'm just looking for a possibility to make the value of the control increase faster at higher values...

0 Kudos
Message 4 of 12
(6,026 Views)

gdargaud:

 

Trying to do so leads to some funny effects, that I cannot explain at all. 🙂 There's a kind of struggle between the INC property and my own increment value. What would you set as INC property value?

0 Kudos
Message 5 of 12
(6,023 Views)

It's monday morning and too early and too sunny outside to go did for code I wrote a decade ago...   Smiley Sad

 

But I swear it did work to create a power of 2 numeric ! Maybe you have to play with the HOT/NORMAL properties. I just don't remember.

0 Kudos
Message 6 of 12
(5,987 Views)
Solution
Accepted by topic author Loevenson

hi,

 

attached a very smal example how you could realize this

 

Best Regards, Fabian

Message 7 of 12
(5,959 Views)

Cool, that trick with checking if the button up or down is pressed - is something I really didn't know. 🙂

 

I'll try it on monday (I'm in a short vacation right now and can see only the source code).

 

0 Kudos
Message 8 of 12
(5,942 Views)

Yes, this information about the eventData1 looks nice.

 

I am wondering if this information could be provided for EVENT_VAL_CHANGED, too?

According to the current help there is no eventData information for EVENT_VAL_CHANGED for numeric controls...

0 Kudos
Message 9 of 12
(5,939 Views)

I don't think passing mouse pointer info does make sense in EVENT_VAL_CHANGED: you may be typing in with the keyboard on a control while the mouse is on a very different control or even on another panel or no panel at all!

 

I was surprised by Fabian trick to detect up/down information until I realized it is based on absolute control position on screen: to make it portable you must discriminate based on control top and height attributes (down if mouse below top + height/2); as an alternative you may call GetRelativeMouseState to obtain coordinates relative to control itself and again compare it with half the control height.

 

But be warned that when coming to customize keyboard behaviour things result to be more complicated that you can imagine: to make this example really useful in real world you must at least

- handle keyboard typing: simple numbers, del and backspace keys...

- handle up/down arrow keys

- trim up/down algorithm to properly handle boundary cases (at present clicking down from value 100 gives 1!)

I don't want to underestimate Fabian effort to propose a solution: he deserves kudos for the good job; it's just that I tried in the past to customize control behaviour and found that it's not so simple as it may appear. Question is: suppose you spend an hour customizing the control and making it portable across all the application, is this worth the time/cost?



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?
0 Kudos
Message 10 of 12
(5,921 Views)