Sign in to follow this  
Followers 0
nassausky

Simple toolbar with macro buttons

8 posts in this topic

Hi,

I was interested in creating a vertical toolbar along the left of my screen which has like 40 buttons top to bottom listing 40 employees. When I click on each it would send their name and enter key to an open web page.  Seems simple enough.  I found the documentation on how to send text to notepad but there is no mention in the documentation how to create a toolbar and set up a button on it to perfom an action.

Does anyone know if there any help on creating a button creation with send text fuctionality or videos. It would be nice if there was a gui that made the buttons and a propertie panel that allowed you to add send to the action of the button.

Thanks!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

something like this?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 100,@DesktopHeight, 1,1,$GUI_SS_DEFAULT_GUI, $WS_EX_TOOLWINDOW)
$Button1 = GUICtrlCreateButton("Button1", 24, 32, 57, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $Button1
            Run("notepad.exe")
          WinWait("[CLASS:Notepad]")
        ControlSend("[CLASS:Notepad]", "", "Edit1", "This is a line of text in the notepad window")


    EndSwitch
WEnd
Edited by Danyfirex

 

venezuela.png Would you like to say thank to Danyfirex using a warmy way?  offer me a cup of coffee... coffee.png

autoit_scripter_blue_userbar.png

       AutoIt...

 

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Create a vertical rebar, and add a toolbar into it

helpfile for

_GUICtrlRebar_Create...must include style = $CCS_VERT

_GUICtrlToolbar_Create...must include style = $TBSTYLE_WRAPABLE

 

using the _GuiCtrlRebar_create example (helpfile), change the following to:

; create the rebar control
    $hReBar = _GUICtrlRebar_Create($hgui, BitOR($CCS_TOP, $WS_BORDER, $RBS_VARHEIGHT, $RBS_AUTOSIZE, $RBS_BANDBORDERS,$CCS_VERT,$RBS_VARHEIGHT ))


    ; create a toolbar to put in the rebar
    $hToolbar = _GUICtrlToolbar_Create($hgui, BitOR($TBSTYLE_FLAT, $CCS_NORESIZE, $CCS_NOPARENTALIGN,$TBSTYLE_WRAPABLE))

looping through button creation can be just as easy...add the controlid's into an array, and then it's easy to see the button being pressed as well

Edited by jdelaney
1 person likes this

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Thanks I should have said multiple buttons vertically because after I setup your sample Danyfirex, I saw how simple that was but how unpleasant it was to start adding more buttons. I tried to create use $ypos+-=25 to the top position of each button but that didn't work.

The code you mentioned jdelaney is a bit too advanced for me at the moment so this below is what I wanted but there i logic wrong in me shifting each button down by 25 units.

AZJIO I love that application and wanted to make something more basic like below. Actually I like the style you made. Is that a white menu that we click on each item? Do you have basic code to setup a menu like that with static send text.

include <GUIConstantsEx.au3>
Global $xpos, $yPos=0, $width=200

$targetwindow="Untitled - Notepad"
Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
$mainwindow = GUICreate("Employee Macros", 200, 900);Width Height
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

;----------------------------------------
$employee1=GUICtrlCreateButton("Button 1", $xPos, $yPos+=25, $width)
$employee2=GUICtrlCreateButton("Button 2", $xPos, $yPos+=25, $width)
$employee3=GUICtrlCreateButton("Button 3", $xPos, $yPos+=25, $width)
;----------------------------------------

;----------------------------------------
GUICtrlSetOnEvent($employee1, "Employee1func")
GUICtrlSetOnEvent($employee2, "Employee2func")
GUICtrlSetOnEvent($employee3, "Employee3func")
;----------------------------------------
GUISetState(@SW_SHOW)

While 1
  Sleep(1000)  ; Idle around
WEnd

Func Employee1func()
  WinActivate($targetwindow)
  Send("Info for employee1{ENTER}")
EndFunc

Func Employee2func()
  WinActivate($targetwindow)
  Send("Info for employee2{ENTER}")
EndFunc

Func Employee3func()
  WinActivate($targetwindow)
  Send("Info for employee3{ENTER}")
EndFunc

Func CLOSEClicked()
  Exit
EndFunc

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Check out what I posted here:

You can create an array, and dynamically produce your GUI...that way, you just add to the array, rather than worrying about recalculating your gui (I'm a fan of data driven scripts/guis)

added controlsettext to quickly input the text...also a much better method than send or controlsend, which can loose focus on the window, and cause sends to other windows...or can loose some text while sending if the window can't accept the letters quickly enough

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
$PID = Run ("notepad")
$tempPID = ""
$hWin = ""
$bContinueLoop = True
While Not IsHWnd($hWin)
    $aWin = WinList("[CLASS:Notepad]")
    For $i= 0 To UBound($aWin) - 1
        _WinAPI_GetWindowThreadProcessId($aWin[$i][1], $tempPID)
        If $tempPID = $PID Then
            $hWin =  $aWin[$i][1]
            ExitLoop
        EndIf
    Next
WEnd

Global Enum $iEmployee_1D_1, _
    $iEmployee_1D_2, _
    $iEmployee_1D_3, _
    $iEmployee_1D_4, _
    $iEmployee_1D_UBound
Global Enum $iEmployee_2d_ButtonText, _
    $iEmployee_2d_Button, _
    $iEmployee_2d_Text, _
    $iEmployee_2d_UBound
Global $aEmployees[$iEmployee_1D_UBound][$iEmployee_2d_UBound]

$aEmployees[$iEmployee_1D_1][$iEmployee_2d_Text] = "Info for employee1" & @CRLF
$aEmployees[$iEmployee_1D_2][$iEmployee_2d_Text] = "Info for employee2" & @CRLF
$aEmployees[$iEmployee_1D_3][$iEmployee_2d_Text] = "Info for employee3" & @CRLF
$aEmployees[$iEmployee_1D_4][$iEmployee_2d_Text] = "Info for employee4" & @CRLF
$aEmployees[$iEmployee_1D_1][$iEmployee_2d_ButtonText] = "Button 1"
$aEmployees[$iEmployee_1D_2][$iEmployee_2d_ButtonText] = "Button 2"
$aEmployees[$iEmployee_1D_3][$iEmployee_2d_ButtonText] = "Button 3"
$aEmployees[$iEmployee_1D_4][$iEmployee_2d_ButtonText] = "Button 4"

Global $xpos, $yPos=0, $width=200, $iButtonHeight = 20, $iButtonSpacing = 5

$targetwindow="Untitled - Notepad"
$mainwindow = GUICreate("Employee Macros", $width+(2*$iButtonSpacing), ($iButtonHeight*$iEmployee_1D_UBound)+(($iButtonSpacing+1)*$iEmployee_1D_UBound));Width Height
;----------------------------------------
For $i = 0 To UBound($aEmployees) - 1
    $aEmployees[$i][$iEmployee_2d_Button] = GUICtrlCreateButton($aEmployees[$i][$iEmployee_2d_ButtonText], $iButtonSpacing, ($iButtonSpacing*(1+$i))+$iButtonHeight*$i,$width,$iButtonHeight )
Next
;----------------------------------------
GUISetState(@SW_SHOW)
WinActivate($mainwindow)

While 1
    $nMsg = GUIGetMsg()
    If Not WinExists($hWin) Then
        MsgBox(1,1,"notepad was closed",2)
        Exit
    EndIf
    For $i = 0 To UBound($aEmployees)-1
        If $nMsg = $aEmployees[$i][$iEmployee_2d_Button] Then
            $text = ControlGetText($hWin, "", "[CLASS:Edit; INSTANCE:1]")
            ControlSetText($targetwindow, "", "[CLASS:Edit; INSTANCE:1]", $text & $aEmployees[$i][$iEmployee_2d_Text])
            ExitLoop
        EndIf
    Next
    If $nMsg = $GUI_EVENT_CLOSE Then
        WinClose($hWin)
        Exit
    EndIf
WEnd
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

; Пример показывает, что не обязательно использовать цикл проверки событий для однотипных элементов. Достаточно указать диапазон в конструкции Switch
; The example shows that it isn't obligatory to use separate events in a loop for the same elements. Sufficient to indicate the range in design Switch

$hGui = GUICreate('My Program', 100, 550)

$iCount = 21 ; Количество пунктов      (The number of items)
$iRows = 100 ; Количество строк      (The number of rows)
Global $BoxConfig[$iCount + 1] = [$iCount], $a[10] = [1, 0, $iRows, 0, 0, 26, 100, -1, 1]
; a[0] - X-координата элемента        (The X-coordinate of the element)
; a[1] - Y-координата элемента        (The Y-coordinate of the element)
; a[2] - Количество строк в блоке      (The number of rows in the block)
; a[3] - X-координата блока      (The X-coordinate of the box)
; a[4] - Y-координата блока      (The Y-coordinate of the box)
; a[5] - Вертикальный шаг в блоке      (Vertical step in block)
; a[6] - Горизонтальный шаг в блоке      (Horizontal step in block)
; a[7] - Индекс текущей колонки     (The index of the current column)
; a[8] - Индекс пункта следующей колонки        (Index of item of the next column)
For $i = 1 To $iCount
    _NextItem($a, $i)
    $BoxConfig[$i] = GUICtrlCreateButton("Check " & $i, $a[0], $a[1], 96, 24)
Next
$a = 0
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $BoxConfig[1] To $BoxConfig[$BoxConfig[0]]
            $j = $nMsg - $BoxConfig[1] + 1
            MsgBox(0, 'Check', $j, 0, $hGui)
            ; Call('Employee' & $j & 'func')
            Employeefunc($j)
        Case -3
            Exit
    EndSwitch
WEnd

Func _NextItem(ByRef $a, $i)
    If $i = $a[8] Then
        $a[8] += $a[2]
        $a[7] += 1
    EndIf
    $a[0] = $a[7] * $a[6] + $a[3] ; X
    $a[1] = $a[4] + Mod($i - 1, $a[2]) * $a[5] ; Y
EndFunc   ;==>_NextItem

; Func _NextItem2(ByRef $a, $i)
; $a[0] = (Ceiling($i / $a[2]) - 1) * $a[6] + $a[3] ; X
; $a[1] = $a[4] + Mod($i - 1, $a[2]) * $a[5] ; Y
; EndFunc   ;==>_NextItem2

Func Employeefunc($j)
    Switch $j
        Case 1
            MsgBox(0, 'Yes?', '111')
        Case 2
            MsgBox(0, 'Yes?', '222')
        Case 3
            MsgBox(0, 'Yes?', '333')
        ; ...
        ; Case n
            ; MsgBox(0, 'Yes?', 'nnn')
        Case Else
            MsgBox(0, 'Yes?', '444')
    EndSwitch
EndFunc   ;==>Employeefunc

http://pastebin.com/cBna5Sv3

1 person likes this

Share this post


Link to post
Share on other sites

Thanks jdelaney and AZJIO!  Excellent and they are 2 different ways to do it/

Share this post


Link to post
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
Sign in to follow this  
Followers 0