Jump to content

Only enable certain characters in a GUICtrlInput


CalBoy
 Share

Recommended Posts

  • Moderators

CalBoy,

This should do what you want: ;)

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)
$hInput = GUICtrlCreateInput("", 10, 10, 300, 20)
$hButton = GUICtrlCreateButton("Exit", 10, 100, 80, 30)
GUISetState(@SW_SHOW)

$sLastText = ""

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $hButton
            Exit
    EndSwitch

    ; Read input text
    $sCurrText = GUICtrlRead($hInput)
    ; If there is a space
    If StringRegExp($sCurrText, '\x20') Then
        ; Then delete it
        GUICtrlSetData($hInput, StringRegExpReplace($sCurrText, '\x20', ""))
        $sLastText = GUICtrlRead($hInput)
    EndIf
WEnd

All clear? :blink:

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

 

Link to comment
Share on other sites

Thank you both very much. M23 you are a champion. That worked perfectly. Can't thank you enough how much you have helped me. Could I ask one more favour?

I'm having trouble writing to a text document during a deployment process. When the script writes lines into the text file currently it errors sometimes when the line has " in it, instead of putting one " in it puts two. So a line that should be cmd.exe /c "etc etc", turns into cmd.exe /c ""etc etc"". Now for AutoIT if I am putting a " in a line I have to use "" in the line correct? I can't see what I have done wrong. Now below I have had to cut down the script as it contains sensitive data I'm afraid :/ but could you see if I have written anything wrong? Thanks alot.

$name = GUICtrlRead($Computername)
$softchoice = GUICtrlRead($installlist)

_FileCreate("x:\sysprep.inf")
$sysprep = FileOpen("x:\sysprep.inf", 1)

FileWriteLine($sysprep, "[UserData]")
FileWriteLine($sysprep, "    FullName=""Admin""")
FileWriteLine($sysprep, "    OrgName=""Awesome""")
FileWriteLine($sysprep, "    ComputerName=" & $name)

FileWriteLine($sysprep, "")
FileWriteLine($sysprep, "[sysprep]")
FileWriteLine($sysprep, "")
FileWriteLine($sysprep, "[GuiRunOnce]")
FileWriteLine($sysprep, "Command0=""cmd /c etc command""")
If $softchoice = "None" Then
Else
    FileWriteLine($sysprep, "Command0=""cmd /c rundll32.exe user32.dll, LockWorkStation""")
    If $softchoice = "Default" Then
        FileWriteLine($sysprep, "Command0=""cmd /c SENSITIVE""")
        FileWriteLine($sysprep, "Command0=""cmd /c SENSITIVE""")
    Else
    EndIf
    If $softchoice = "Computing" Then
        FileWriteLine($sysprep, "Command0=""cmd /c SENSITIVE""")
        FileWriteLine($sysprep, "Command0=""cmd /c SENSITIVE""")
        FileWriteLine($sysprep, "Command0=""cmd /c SENSITIVE""")
    Else
    EndIf
EndIf
FileWriteLine($sysprep, "Command0=""cmd /c SENSITIVE""")
FileWriteLine($sysprep, "Command0=""cmd /c SENSITIVE""")

FileClose($sysprep)

If I haven't made sense please tell me! Any help would be awesome. Thanks heaps.

CalBoy

Link to comment
Share on other sites

OH!

And how could I go around disabling editing in a combo box? Like one of those drop down lists. Currently when users pick a item out of the list they can sometimes put a space in on the end or delete a character without noticing, this then causes the script to error when it looks for that variable. Is there a way to stop the combo box from being edited but still have the different choices within it?

Thanks,

CalBoy

Link to comment
Share on other sites

  • Moderators

CalBoy,

Would Sir like fries with that? :P

I have never liked the multiple quote method - I prefer to use single and double quotes like this: ;)

$name = GUICtrlRead($Computername)
$softchoice = GUICtrlRead($installlist)

$sysprep = FileOpen(@scriptdir & "\sysprep.inf", 2)

FileWriteLine($sysprep, '[UserData]')
FileWriteLine($sysprep, '    FullName="Admin"')
FileWriteLine($sysprep, '    OrgName="Awesome"')
FileWriteLine($sysprep, '    ComputerName=' & $name)

FileWriteLine($sysprep, '')
FileWriteLine($sysprep, '[sysprep]')
FileWriteLine($sysprep, '')
FileWriteLine($sysprep, '[GuiRunOnce]')
FileWriteLine($sysprep, 'Command0="cmd /c etc command"')

If $softchoice <> "None" Then
    FileWriteLine($sysprep, 'Command0="cmd /c rundll32.exe user32.dll, LockWorkStation"')
    If $softchoice = "Default" Then
        FileWriteLine($sysprep, 'Command0="cmd /c SENSITIVE"')
        FileWriteLine($sysprep, 'Command0="cmd /c SENSITIVE"')
    ElseIf $softchoice = "Computing" Then
        FileWriteLine($sysprep, 'Command0="cmd /c SENSITIVE"')
        FileWriteLine($sysprep, 'Command0="cmd /c SENSITIVE"')
        FileWriteLine($sysprep, 'Command0="cmd /c SENSITIVE"')
    EndIf
EndIf
FileWriteLine($sysprep, 'Command0="cmd /c SENSITIVE"')
FileWriteLine($sysprep, 'Command0="cmd /c SENSITIVE"')

FileClose($sysprep)

which gives me this file:

[UserData]
    FullName="Admin"
    OrgName="Awesome"
    ComputerName=elvis

[sysprep]

[GuiRunOnce]
Command0="cmd /c etc command"
Command0="cmd /c rundll32.exe user32.dll, LockWorkStation"
Command0="cmd /c SENSITIVE"
Command0="cmd /c SENSITIVE"

You will also note that I have made one or two changes to the code:

- As it says in the Help file: "Opening a file in write mode creates the file if it does not exist" - so you do not need the _FileCreate line.

- The If structure was a little "strange". :blink:

As for the combo box, you need the $CBS_DROPDOWNLIST style - not something that jumps out at you when you first look for a non-editable combo: :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>

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

GUICtrlCreateLabel("Normal editable combo", 10, 10, 200, 20)
GUICtrlCreateCombo("", 10, 30, 230, 20)
GUICtrlSetData(-1, "tom|dick|harry")

GUICtrlCreateLabel("Non-editable combo", 10, 100, 200, 20)
GUICtrlCreateCombo("", 10, 120, 230, 20, BitOR($CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_DROPDOWNLIST))
GUICtrlSetData(-1, "tom|dick|harry")

GUISetState()

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

Is that it for a while? :nuke:

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

 

Link to comment
Share on other sites

Hi guys,

How do I disable spaces in a input within a GUI? Is there a special function for it?

Thanks in advance,

CalBoy

You could also intercept the WM_COMMAND message to do your space-suppression only when that specific control is actually being updated:

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

$hGUI = GUICreate("Test", 500, 500)
$hInput = GUICtrlCreateInput("", 10, 10, 300, 20)
$hButton = GUICtrlCreateButton("Exit", 10, 100, 80, 30)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

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

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode    = BitShift($wParam, 16)       ;HiWord
    $nID            = BitAnd($wParam, 0x0000FFFF) ;LoWord
    If $nID = $hInput And $nNotifyCode = 768 Then ; control was updated
        GUICtrlSetData($hInput, StringStripWS(GUICtrlRead($hInput), 2))
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

Edit: Or even just:

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    If BitAnd($wParam, 0x0000FFFF) = $hInput Then GUICtrlSetData($hInput, StringStripWS(GUICtrlRead($hInput), 2))
    Return $GUI_RUNDEFMSG
EndFunc
Edited by Spiff59
Link to comment
Share on other sites

  • Moderators

Spiff59,

Nice! Shows the difference between a real coder and a hobbyist! :blink:

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

 

Link to comment
Share on other sites

Spiff59,

Nice! Shows the difference between a real coder and a hobbyist! :blink:

M23

Not to turn Calboy's thread into a lovefest, but...

Besides being one of the most giving/helpful persons around here, I think you're a good ways past hobbyist stage!

I can rattle off EBCDIC conversions, or CICS TranID's, or some System360 opcodes, but they're of no use around here. I'm generally lost regarding Windows internals.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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