Jump to content

GUICtrlCreateCombo SetLimit ?


Merchants
 Share

Recommended Posts

GUICtrlSetLimit() Can be used for Up/Down, slider, edit, input and list controls but I don't think it has any effect on a combobox.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

A ComboBox only presents choices presented by the application in the control, so limits don't make sense there. But you can have an Edit control (input) subclassed on to the ComboBox and maybe you could apply it to that. I haven't tried it, but you might get the handle to the edit with _GUICtrlComboBoxEx_GetEditControl() and set a limit on that.

:graduated:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The contents of a combo box are set by the programmer, don't use more characters than you want displayed in your combo box and you won't need to try and set a limit. A user can type in a combo box, but if you only check for the contents that you put into it, then that shouldn't be an issue.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

Merchants,

Here is one way to do it: :graduated:

#include <GUIConstantsEx.au3>
#Include <GuiComboBox.au3>

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

$hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
GUICtrlSetData($hCombo, "Option1|Option2")

$hComboDummy = GUICtrlCreateDummy()

GUISetState()

Global $AccelKeys[1][2]=[["{ENTER}", $hComboDummy]]
GUISetAccelerators($AccelKeys)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hComboDummy
            ContinueCase
        Case $hCombo
            ConsoleWrite(GUICtrlRead($hCombo) & @CRLF)
    EndSwitch

    $sText = GUICtrlRead($hCombo)
    If StringLen($sText) > 10 Then
        $sText = StringMid($sText, 1, 10)
        _GUICtrlComboBox_SetEditText($hCombo, $sText)
    EndIf

WEnd

There are probably sexier ways to do it by getting the handle of the edit control and and looking for $EN_CHANGE messages, but this works for me! :(

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

This was what I meant, and you don't have to monitor it at all:

#include <GuiConstantsEx.au3>
#include <GuiEdit.au3>
#include <GuiComboBoxEx.au3>

Global $hGUI, $hCombo, $hEdit

; Create GUI
$hGUI = GUICreate("ComboBoxEx Get Edit Control", 400, 300)
$hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 394, 268)
For $x = 0 To 5
    _GUICtrlComboBoxEx_AddString($hCombo, StringFormat("%03d : Random string", Random(1, 100, 1)))
Next
$hEdit = _GUICtrlComboBoxEx_GetEditControl($hCombo)
_GUICtrlEdit_SetLimitText($hEdit, 16)
GUISetState()

; Loop until user exits
MsgBox(64, "Limit", "ComboBox Edit control limit = " & _GUICtrlEdit_GetLimitText($hEdit))
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

:graduated:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

Just for completeness, here is a way to limit the number of characters using the Windows message as I mentioned above: :graduated:

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

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

$hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
$hCombo_Handle = GUICtrlGetHandle($hCombo)
GUICtrlSetData($hCombo, "Option 1|Option 2")

GUISetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg
    Local $hWndFrom = $lParam
    Local $iCode = BitShift($wParam, 16) ; Hi Word
    Switch $hWndFrom
        Case $hCombo_Handle
            Switch $iCode
                Case $CBN_EDITCHANGE ; Sent after the user has altered the text in the edit control portion of a combo box
                    $sText = GUICtrlRead($hCombo)
                    If StringLen($sText) > 10 Then
                        $sText = StringMid($sText, 1, 10)
                        _GUICtrlComboBox_SetEditText($hCombo, $sText)
                    EndIf
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc

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

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...