Jump to content

pressing a Guibutton and pasting something in the current GUI field


 Share

Recommended Posts

Hey i want to make a few GUI buttons ,

when a button is pressed i want it to put some text in a gui input field....

i have the buttons and i have the field but i cant find a way to make a text go into that field when i press the button....

thanks..

i made 20+ buttons each have a differnt symbol and needs to paste differnt text...

this is one of the icons for example...

$icons[11] = GUICtrlCreateButton ( "{{}W{}}", 370 , 340 , 25 , 25, $BS_BITMAP )

GUICtrlSetImage ( -1, @ScriptDir & "\Symbols\" & "W.bmp" )

thanks

Link to comment
Share on other sites

Like this?

#include <GuiConstants.au3>

Opt("GuiOnEventMode", 1)

Global $aButton[21]
$aButton[0] = 20

Dim $ButtonLeft = 20
Dim $ButtonTop = 20

$hGUI = GUICreate("Test GUI", 340, 300)
GUISetOnEvent(-3, "_Exit")

For $i = 1 To $aButton[0]
    If ($i = 6) Or ($i = 11) Or ($i = 16) Then
        $ButtonTop += 60
        $ButtonLeft = 20
    EndIf
    
    $aButton[$i] = GUICtrlCreateButton(Chr($i + 64), $ButtonLeft, $ButtonTop, 50, 50, $BS_ICON)
    GUICtrlSetImage(-1, "shell32.dll", $i)
    GUICtrlSetOnEvent(-1, "_SetText")
    $ButtonLeft += 60
Next

$hInput = GUICtrlCreateInput("", 20, 270, 290, 20)

GUISetState()

While 1
    Sleep(100)
WEnd

Func _Exit()
    Exit
EndFunc

Func _SetText()
    Local $iText = GUICtrlRead(@GUI_CtrlId)
    GUICtrlSetData($hInput, $iText)
EndFunc
:)
Link to comment
Share on other sites

Almost ... only missing 2 things...

1. I have a lot of "GUICtrlCreateInput"

using your script i cant put the data on the current GUICtrlCreateInput (when the mouse is currently at)

2. pressing the button will delete the input already there and put a new input (i want to add input to the input already there)..

what i tried to do is something like this

$currfocus = ""

$lastfocus = ""

$msg = 0

$prevmsg = 0

While $msg <> $GUI_EVENT

$msg = GUIGetMsg()

$prevmsg = $msg

WEnd

For $i = 0 To $iconsnum-1

If ( $msg == $icons[$i] ) Then

If ( StringLeft ( $lastfocus, 4 ) == "Edit" ) Then

ControlFocus ( "Configuration Panel", "", $lastfocus )

Send ( GUICtrlRead ( $msg ) )

EndIf

EndIf

Next

EDIT////

OK im left only with the problem that the data gets deleted every time i press the button,,

thanks/

OK i dont get it ...

i manage to solve my problem but in a trial and error kinda way..

thats part of the code in the end ( i managed to make it work but i dont really know how>?

GUISetState ()
$currfocus = ""
$lastfocus = ""
$msg = 0
$prevmsg = 0
While $msg <> $GUI_EVENT    
$msg = GUIGetMsg()
$prevmsg = $msg
;$prevmsg = 0
    If ( $currfocus <> ControlGetFocus ($botname)) Then
    $lastfocus = $currfocus
        $currfocus = ControlGetFocus ( $botname)
    EndIf
        For $i = 0 To $iconsnum-1 step 1
        If ( $msg == $icons[$i] ) Then
            If  ( StringLeft ( $lastfocus, 4 ) == "Edit" ) Then
                ControlFocus ($botname, " ", $lastfocus )

                if $lastfocus="Edit4" Then
                    $tempdata=(GUICtrlRead($msg))
                    $tempdata2= GUICtrlRead ($Sell_Messege)&$tempdata
                    GUICtrlSetData ($Sell_Messege,$tempdata2)
                EndIf
                if $lastfocus="Edit3" Then
                    $tempdata=(GUICtrlRead($msg))
                    $tempdata2= GUICtrlRead ($BUY_Messege)&$tempdata
                    msgbox (4096, "you pressed,", $tempdata)
                    GUICtrlSetData ($BUY_Messege,$tempdata2)
                    EndIf
            EndIf
        EndIf
    Next
Edited by mrbig1479
Link to comment
Share on other sites

Almost ... only missing 2 things...

1. I have a lot of "GUICtrlCreateInput"

using your script i cant put the data on the current GUICtrlCreateInput (when the mouse is currently at)

2. pressing the button will delete the input already there and put a new input (i want to add input to the input already there)..

what i tried to do is something like this

$currfocus = ""

$lastfocus = ""

$msg = 0

$prevmsg = 0

While $msg <> $GUI_EVENT

$msg = GUIGetMsg()

$prevmsg = $msg

WEnd

For $i = 0 To $iconsnum-1

If ( $msg == $icons[$i] ) Then

If ( StringLeft ( $lastfocus, 4 ) == "Edit" ) Then

ControlFocus ( "Configuration Panel", "", $lastfocus )

Send ( GUICtrlRead ( $msg ) )

EndIf

EndIf

Next

EDIT////

OK im left only with the problem that the data gets deleted every time i press the button,,

thanks/

OK i dont get it ...

i manage to solve my problem but in a trial and error kinda way..

thats part of the code in the end ( i managed to make it work but i dont really know how>?

GUISetState ()
$currfocus = ""
$lastfocus = ""
$msg = 0
$prevmsg = 0
While $msg <> $GUI_EVENT    
$msg = GUIGetMsg()
$prevmsg = $msg
;$prevmsg = 0
    If ( $currfocus <> ControlGetFocus ($botname)) Then
    $lastfocus = $currfocus
        $currfocus = ControlGetFocus ( $botname)
    EndIf
        For $i = 0 To $iconsnum-1 step 1
        If ( $msg == $icons[$i] ) Then
            If  ( StringLeft ( $lastfocus, 4 ) == "Edit" ) Then
                ControlFocus ($botname, " ", $lastfocus )

                if $lastfocus="Edit4" Then
                    $tempdata=(GUICtrlRead($msg))
                    $tempdata2= GUICtrlRead ($Sell_Messege)&$tempdata
                    GUICtrlSetData ($Sell_Messege,$tempdata2)
                EndIf
                if $lastfocus="Edit3" Then
                    $tempdata=(GUICtrlRead($msg))
                    $tempdata2= GUICtrlRead ($BUY_Messege)&$tempdata
                    msgbox (4096, "you pressed,", $tempdata)
                    GUICtrlSetData ($BUY_Messege,$tempdata2)
                    EndIf
            EndIf
        EndIf
    Next
GuiCtrlSetData($Input, GUICtrlRead($input) & " Whatever the button sends")

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