Jump to content

Echo input to a label


c.haslam
 Share

Recommended Posts

I have an input box and a label (and lots of other stuff too). As the user types in the input box, I want the text to appear as the label caption. I suspect that the answer lies somewhere in:

  • Using a combo box rather than an input box
  • When creating the combo box, making the style $CBS_NOINTEGRALHEIGHT
  • GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") and writing a WM_COMMAND function
  • calling _GUICtrlComboBox_GedEditText() to retrieve the entered text

but so far I am getting nowhere. Any suggestions?

...chris

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

Hi! Try this example:

#include <GuiConstants.au3>

$hGui = GuiCreate("Test GUI", 300, 180)

$hLabel = GUICtrlCreateLabel("", 50, 10, 200, 16)
GUICtrlSetBkColor(-1, 0xC0C0C0)

$hInput = GUICtrlCreateInput("", 50, 50, 200, 16)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $IdFrom, $iCode
    
    $IdFrom = BitAND($wParam, 0xFFFF)
    $iCode = BitShift($wParam, 16)
    
    Switch $IdFrom
    Case $hInput
        Switch $iCode
        Case $EN_UPDATE
            GUICtrlSetData($hLabel, GUICtrlRead($hInput))
        EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
:)
Link to comment
Share on other sites

I have an input box and a label (and lots of other stuff too). As the user types in the input box, I want the text to appear as the label caption. I suspect that the answer lies somewhere in:

  • Using a combo box rather than an input box
  • When creating the combo box, making the style $CBS_NOINTEGRALHEIGHT
  • GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") and writing a WM_COMMAND function
  • calling _GUICtrlComboBox_GedEditText() to retrieve the entered text

but so far I am getting nowhere. Any suggestions?

...chris

Example:

#include <GuiConstantsEx.au3>
#include <GuiComboBox.au3>

$hGui = GuiCreate("Test GUI", 300, 180)

$hLabel = GUICtrlCreateLabel("", 50, 10, 200, 16)
GUICtrlSetBkColor(-1, 0xC0C0C0)

$hCombo = _GUICtrlComboBox_Create($hGui, "Combo", 50, 50, 200, 16, $CBS_NOINTEGRALHEIGHT)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $hWndFrom, $iCode, $iText
    
    $hWndFrom = $lParam
    $iCode = BitShift($wParam, 16)
    
    Switch $hWndFrom
    Case $hCombo
        Switch $iCode
        Case $CBN_EDITUPDATE
            $iText = _GUICtrlComboBox_GetEditText($hCombo)
            GUICtrlSetData($hLabel, $iText)
        EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
:)
Link to comment
Share on other sites

Here is another simple one

$hGui = GuiCreate("Test GUI", 300, 180)

$hLabel = GUICtrlCreateLabel("", 50, 10, 200, 16)
GUICtrlSetBkColor(-1, 0xC0C0C0)

$hInput = GUICtrlCreateInput("", 50, 50, 200, 16)
GUISetState()
While 1
   $Msg = GUIGetMsg()
   If $Msg = -3 Then Exit
  ;; Check the contents before making changes to the label to avoid flickering
   If GUICtrlRead($hInput) <> GUICtrlRead($hLabel) Then GUICtrlSetData($hLabel, GUICtrlRead($hInput))
Wend

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

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