Jump to content

Recommended Posts

Posted (edited)

Hello

One good lad gave me the following code

#include <GuiConstantsEx.au3> 
#include <EditConstants.au3> 
 
Global $Last_Set_Value = 0 
 
$GUI = GUICreate("Test Script", 300, 200) 
 
$Input = GUICtrlCreateInput(0, 20, 40, 80, 20, BitOR($ES_LEFT, $ES_AUTOHSCROLL, $ES_READONLY)) 
$UpDown = GUICtrlCreateUpdown($Input) 
GUICtrlSetBkColor($Input, 0xFFFFFF) 
 
GUISetState(@SW_SHOW, $GUI) 
 
While 1 
    $nMsg = GUIGetMsg() 
    Switch $nMsg 
        Case $GUI_EVENT_CLOSE 
            Exit 
        Case $UpDown 
            Local $Input_Value = Number(GUICtrlRead($Input)) 
 
            If $Input_Value > $Last_Set_Value Then 
                $Last_Set_Value += 0.1 
            ElseIf $Input_Value < $Last_Set_Value Then 
                $Last_Set_Value -= 0.1 
            EndIf 
 
            GUICtrlSetData($Input, $Last_Set_Value) 
    EndSwitch 
WEnd

The task is to change numbers in '$Input' box with the step 0.1 But the code has several bugs and I can't figure out where they occur.

Bug 1. The max number is 5.9 only

Bug 2. The min number is -5.9 only

Bug 3. If I do, for example, 5 clicks on UP arrow to increase the number then I must do the 5-1=4 clicks on down arrow to start decreasing numbers.

Can you kindly fix it? Thanks

Edited by Tipulatoid
Posted

Kinda bugged that script ...

Here is a working one:

#include <GuiConstantsEx.au3> 
#include <EditConstants.au3> 

Global $Last_Set_Value = 0 

$GUI = GUICreate("Test Script", 300, 200) 

$Input = GUICtrlCreateInput(0, 20, 40, 80, 20, BitOR($ES_LEFT, $ES_AUTOHSCROLL, $ES_READONLY)) 
$UpDown = GUICtrlCreateUpdown($Input) 
GUICtrlSetBkColor($Input, 0xFFFFFF) 

GUISetState(@SW_SHOW, $GUI) 

While 1 
    $nMsg = GUIGetMsg() 
    Switch $nMsg 
        Case $GUI_EVENT_CLOSE 
            Exit 
        Case $UpDown 
            If Mod(GUICtrlRead($Input), 10) = 0 Then
                GUICtrlSetData($Input, GUICtrlRead($Input)/10&".0")
            Else
                GUICtrlSetData($Input, GUICtrlRead($Input)/10)
            EndIf
    EndSwitch 
WEnd

good luck,

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Posted

Kinda bugged that script ...

Here is a working one:

#include <GuiConstantsEx.au3> 
#include <EditConstants.au3> 

Global $Last_Set_Value = 0 

$GUI = GUICreate("Test Script", 300, 200) 

$Input = GUICtrlCreateInput(0, 20, 40, 80, 20, BitOR($ES_LEFT, $ES_AUTOHSCROLL, $ES_READONLY)) 
$UpDown = GUICtrlCreateUpdown($Input) 
GUICtrlSetBkColor($Input, 0xFFFFFF) 

GUISetState(@SW_SHOW, $GUI) 

While 1 
    $nMsg = GUIGetMsg() 
    Switch $nMsg 
        Case $GUI_EVENT_CLOSE 
            Exit 
        Case $UpDown 
            If Mod(GUICtrlRead($Input), 10) = 0 Then
                GUICtrlSetData($Input, GUICtrlRead($Input)/10&".0")
            Else
                GUICtrlSetData($Input, GUICtrlRead($Input)/10)
            EndIf
    EndSwitch 
WEnd

good luck,

greetings enaiman and Tipulatoid

just needs slight tweaking :)

#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <UpDownConstants.au3>

Global $Last_Set_Value = 0

$GUI = GUICreate("Test Script", 300, 200)

; UP/Down control locks up at 1000 (100) without $UDS_NOTHOUSANDS style and GUICtrlSetLimit()
$Input = GUICtrlCreateInput(0, 20, 40, 80, 20, BitOR($ES_LEFT, $ES_AUTOHSCROLL, $ES_READONLY))
; $UDS_NOTHOUSANDS Prevents insertion of a thousands separator between every three decimal positions.
; $UDS_ARROWKEYS up-down control processes the UP and DOWN ARROW keys.
$UpDown = GUICtrlCreateUpdown($Input, BitOR($UDS_NOTHOUSANDS, $UDS_ARROWKEYS))
GUICtrlSetLimit($UpDown, 1000, -1000) ; set up/down range (MAX 32767, MIN -32768)
GUICtrlSetBkColor($Input, 0xFFFFFF)

GUISetState(@SW_SHOW, $GUI)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $UpDown
            If Mod(GUICtrlRead($Input), 10) = 0 Then
                GUICtrlSetData($Input, GUICtrlRead($Input)/10&".0")
            Else
                GUICtrlSetData($Input, GUICtrlRead($Input)/10)
            EndIf
    EndSwitch
WEnd

I see fascists...

Posted

enaiman, rover, thanks a lot! And one more question - how can I edit topic's name to add [solved]?

select Full Edit from the Edit button menu on your first post and edit the title line at the top

I see fascists...

Posted (edited)

And if I want to have default number "5", for example, and start increasing / decreasing from it, but not from 5/10=0.5 - is it possible?

my preferred method is to ghost the up/down control with a hidden input 'buddy' control

do the math and use a visible input control on top of the hidden one for displaying the desired format.

I tried UDM_SETPOS32 messages and other methods of presetting a value of 5

but couldn't get anything to work.

also I should have pointed out GUICtrlRead returns a string and needs to be converted to number

what is your desired range for the up/dn?

is a read only control like this ok?

also there is a UDF on the forum for setting acceleration settings for Up/Dn controls

look for _GUICtrlUpdownSetAccel, Author Chris Howes (OjO)

see if this works for you

#include <GuiConstantsEx.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <UpDownConstants.au3>
#include <WinAPI.au3>

Opt("MustDeclareVars", 1)
Global $Last_Set_Value = 0
Global $GUI, $hInput2, $Input1, $Input2, $UpDown
Global $wProcNew, $wProcOld, $nMsg

$GUI = GUICreate("Test Script", 300, 200)
GUISetBkColor(0xFFFFFF)

$Input1 = GUICtrlCreateInput("50", 80, 40, 25, 22, $ES_READONLY) ; hidden buddy input control for GUICtrlCreateUpdown
GUICtrlSetState(-1, $GUI_HIDE) ; hide $Input1

$Input2 = GUICtrlCreateInput("5.0", 20, 40, 70, 22, $ES_READONLY)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
GUICtrlSetBkColor(-1, 0xFFFFFF)
$hInput2 = GUICtrlGetHandle($Input2)

$UpDown = GUICtrlCreateUpdown($Input1, BitOR($UDS_NOTHOUSANDS, $UDS_ARROWKEYS)) ; up-down control processes the UP and DOWN ARROW keys.
GUICtrlSetLimit($UpDown, 1000, -1000) ; set up/down range

; subclass the window/control:
$wProcNew = DllCallbackRegister("_NewWindowProc", "int", "hwnd;uint;wparam;lparam")
$wProcOld = _WinAPI_SetWindowLong($hInput2, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
GUISetState(@SW_SHOW, $GUI)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _WinAPI_SetWindowLong($hInput2, $GWL_WNDPROC, $wProcOld)
            DllCallbackFree($wProcNew)
            Exit
        Case $UpDown
            Local $Input_Value = Number(GUICtrlRead($Input1))
            If $Input_Value <> $Last_Set_Value Then
                $Last_Set_Value = $Input_Value
                If Mod($Input_Value, 10) = 0 Then
                    GUICtrlSetData($Input2, 0.1 * $Last_Set_Value & ".0")
                Else
                    GUICtrlSetData($Input2, 0.1 * $Last_Set_Value)
                EndIf
            EndIf
    EndSwitch
WEnd

; custom callback function: deals with up/dn input control appearance issues when using dummy control
Func _NewWindowProc($hWnd, $Msg, $wParam, $lParam)
    Switch $Msg
        Case $WM_SETFOCUS, $WM_NCHITTEST
            Switch $hWnd
                Case $hInput2
                    Return 0
            EndSwitch
    EndSwitch
    ;pass the unhandled messages to default WindowProc
    Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $Msg, $wParam, $lParam)
EndFunc   ;==>_NewWindowProc
Edited by rover

I see fascists...

Posted

what is your desired range for the up/dn?

I have 24 inputs in one GUI dialogue. The lowest number is always zero, the highest - 9.9 or 99.9 depending on input

is a read only control like this ok?

Yes, it is

see if this works for you

Works just as I needed! I am attaching now your decision into my script.

Thanks, Rover. You helped me a lot.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...