Jump to content

Input box with up\down control but using hex as the input


Go to solution Solved by TwoCanoe,

Recommended Posts

Posted

My example:

#include-once
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

Local $myHex = "88AAFF"

MyGUI()
Func MyGUI()
    $gui = GUICreate("My GUI", 200, 200, 300, 150)
    $input = GUICtrlCreateInput($myHex, 50, 50, 100, 30, $ES_CENTER)
    GUICtrlCreateUpDown(-1)
    
    GUISetState(@SW_SHOW)
    
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_MINIMIZE, $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc

Is it possible to increase\decrease the hex using the up\down of the input box?

  • Moderators
Posted

TwoCanoe,

For simplicity, I would use a dummy input like this:

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

Local $sMyHex = "0000FF"

$hGUI = GUICreate("Test", 500, 500)

$cInput = GUICtrlCreateInput(String($sMyHex), 10, 100, 100, 20, $ES_CENTER)

$cDummyInput = GUICtrlCreateInput(Dec($sMyHex), 110, 100, 20, 20)
$cUpDown = GUICtrlCreateUpdown($cDummyInput)

GUICtrlSetState($cDummyInput, $GUI_FOCUS)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cDummyInput
            GUICtrlSetData($cInput, Hex(Number(GUICtrlRead($cDummyInput)), 6))
    EndSwitch

WEnd

Increase the width of the dummy input to see what is going on.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

Thanks for the quick response Mebla.

I set $sMyHex = "000000" and ran.

I clicked and held the input up button and the hex increased until 0003E7 then goes to 000001 and is no longer accessabile.

Does something similar when I run the script and hold the input's down button.

Your example makes sense but I don't see why the count stops.

Posted (edited)


Was the dot in GUICtrlCreateUpdown

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

Local $sMyHex = "FFFFFF"

$hGUI = GUICreate("Test", 500, 500)
$cInput = GUICtrlCreateInput($sMyHex, 10, 100, 100, 20, $ES_CENTER)
$cDummyInput = GUICtrlCreateInput(Int("0x" & $sMyHex), 110, 100, 100, 20)
$cUpDown = GUICtrlCreateUpdown($cDummyInput)

GUICtrlSetLimit($cUpDown, 16777215, 0) ; Set range for valid 6-digit hex values (0 to FFFFFF)
GUICtrlSetState($cDummyInput, $GUI_FOCUS)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cDummyInput
            ; Remove the dot
            Local $intValue = Int(StringReplace(GUICtrlRead($cDummyInput), ".", ""))
            Local $sHexValue = Hex($intValue, 6) ; Convert to 6-digit hex
            GUICtrlSetData($cInput, $sHexValue)
    EndSwitch
WEnd

 

Edited by ioa747
added WUSRlSetLimit and comments and replace Number with int

I know that I know nothing

  • Solution
Posted

Good catch. Nearly, not a dot but a comma.

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

Local $sMyHex = "FFFFFF"

$hGUI = GUICreate("Test", 500, 500)
$cInput = GUICtrlCreateInput($sMyHex, 10, 100, 100, 20, $ES_CENTER)
$cDummyInput = GUICtrlCreateInput(Number("0x" & $sMyHex), 110, 100, 100, 20)
$cUpDown = GUICtrlCreateUpdown($cDummyInput)

GUICtrlSetLimit($cUpDown, 16777215, 0) ; Set range for valid 6-digit hex values (0 to FFFFFF)
GUICtrlSetState($cDummyInput, $GUI_FOCUS)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cDummyInput
            ; Remove the dot
            Local $iDecimalValue = Number(StringReplace(GUICtrlRead($cDummyInput), ",", ""))    ; CHANGED HERE
            Local $sHexValue = Hex($iDecimalValue, 6) ; Convert to 6-digit hex
            GUICtrlSetData($cInput, $sHexValue)
    EndSwitch
WEnd

Many thanks ioa747

Posted (edited)

Another approach, based on UpDown control messages :

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration

MyGUI()

Func MyGUI()
    Local $Gui, $Input, $h_Updown, $MyHex = "0x88AAFF"

    $Gui = GUICreate("My GUI", 200, 200, 300, 150)
    $Input = GUICtrlCreateInput("", 50, 50, 100, 30, $ES_CENTER)
    $h_Updown = GUICtrlGetHandle(GUICtrlCreateUpDown(-1))

    Local $UDM_SETBASE = $WM_USER + 109 ; in CommCtrl.h
    _SendMessage($h_Updown, $UDM_SETBASE, 16, 0) ; base 16 in this script

    Local $UDM_SETRANGE32 = $WM_USER + 111
    ; _SendMessage($h_Updown, $UDM_SETRANGE32, -1, 0) ; experimented... but changing these values seems to create issues.
    _SendMessage($h_Updown, $UDM_SETRANGE32, 0, 0xFFFFFFFF) ; equivalent to 0, -1

    GUICtrlSetData($Input, $MyHex)
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc

 

Edited by pixelsearch
modified params for $UDM_SETRANGE32
Posted
35 minutes ago, TwoCanoe said:

Good catch. Nearly, not a dot but a comma.


Then it's obvious that it has to do with the regional settings, because for me it was (is) . dot

I know that I know nothing

Posted (edited)

Hi everybody :)
I have 2 remarks concerning this thread :

1) The dot / comma issue described in the preceding posts would not happen if the UpDown control was created like this :

; $cUpDown = GUICtrlCreateUpdown($cDummyInput)
$cUpDown = GUICtrlCreateUpdown($cDummyInput, BitOR($GUI_SS_DEFAULT_UPDOWN, $UDS_NOTHOUSANDS))

Because as seen in the preceding posts, as soon as you reach 1000 (decimal, e.g. 0x3E8 hex) then an issue occurs due to the thousand separator found in the hidden Input control.

2)

6 hours ago, ioa747 said:

Then it's obvious that it has to do with the regional settings, because for me it was (is) . dot

On my computer it's not a dot, it's not a comma... but it's a space that I use as thousand separator in my windows regional settings.

So maybe it could be useful, when necessary, to avoid the hard-coded syntax...

; Remove the dot (or the comma or the space etc...)
; Local $intValue = Int(StringReplace(GUICtrlRead($cDummyInput), ".", ""))
; Local $intValue = Int(StringReplace(GUICtrlRead($cDummyInput), ",", ""))
; Local $intValue = Int(StringReplace(GUICtrlRead($cDummyInput), " ", ""))

...then we could check instead what are the user locale settings, for example in this case, the $sThousandSymbol should do it in all cases :

#include <APILocaleConstants.au3>
#include <WinAPILocale.au3>

Local $iLCID = _WinAPI_GetUserDefaultLCID()

Local $sThousandSymbol = _WinAPI_GetLocaleInfo($iLCID, $LOCALE_STHOUSAND)
ConsoleWrite('Thousand symbol  >>>' & $sThousandSymbol & "<<<" & @crlf) ; usually . or , or space

ConsoleWrite('Decimal  symbol  >>>' & _WinAPI_GetLocaleInfo($iLCID, $LOCALE_SDECIMAL) & "<<<" & @crlf) ; usually . or ,

Let's hope my different approach, using 2 UpDown control messages ($UDM_SETBASE and $UDM_SETRANGE32), solves OP's question in any case, though I'm not satisfied for now with the 2 parameters (-1 and 0) associated to $UDM_SETRANGE32 . I'll try to dig a bit.

Edited by pixelsearch
Posted

Nice work on this one @pixelsearch.  But I do not understand your :

_SendMessage($h_Updown, $UDM_SETRANGE32, -1, 0)

Why not a simple :

_SendMessage($h_Updown, $UDM_SETRANGE32, 0, 0xFFFFFF)

 

Posted (edited)

@Nine exactly, I'm actually preparing a comment about this, I'll update this message in a few min.

Edit: Help file, function GUICtrlCreateUpdown

By default Windows increases the value when clicking the upper arrow button.

Msdn web page, About Up-Down Controls :

Concerning the UDM_SETRANGE message : the maximum position may be less than the minimum, and in that case clicking the up arrow button decreases the current position. To put it another way, up means moving toward the maximum position.

In my initial script above, I first used this syntax...

_SendMessage($h_Updown, $UDM_SETRANGE32, -1, 0)

...without understanding exactly why it worked, when  I was asking for a minimum limit of -1 and a maximum limit of 0, so why did the whole range of 32 bits integers could be displayed when clicking the arrow buttons ?

And also why did the up arrow button decreased the current value instead of increasing it, when -1 < 0 ?

I guess the answer is in the Two complement's, where -1 is equivalent to 0xFFFFFFFF, which means I used in fact :

_SendMessage($h_Updown, $UDM_SETRANGE32, 0xFFFFFFFF, 0)

So now I just changed for the opposite in the script above...

_SendMessage($h_Updown, $UDM_SETRANGE32, 0, 0xFFFFFFFF) ; equivalent to 0, -1

...then the value increases (at last !) when we click the up arrow button and all 32 bits integers are available (in case the user types any integer inside the Input control, then clicks the up or down arrow of the updown control)

 

Edited by pixelsearch

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...