Jump to content

making buttions with array


Go to solution Solved by PhoenixXL,

Recommended Posts

im trying to make a gui editor but i have a problem i need to be able to make an infinate amount of dragable buttons i tryed this but it dosent work

$board = GUICreate('',500,500)
Global $buttons[2]
$buttons[0] = GUICtrlCreateButton("button 1",0,0,20,20)
$buttons[1] = GUICtrlCreateButton("button 2",100,100,20,20)
GUISetState(@SW_SHOW,$board)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
case -7,$buttons[_ArraySearch($button,$nMsg)]
_drag($board,$buttons[_ArraySearch($button,$nMsg)])
EndSwitch
WEnd

All my projects live on github

Link to post
Share on other sites

WOW - I never thought of using _ArraySearch!!

However, your script will crash because _ArraySearch returns -1 if the message code is not found.

Try this instead ...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <array.au3>
$board = GUICreate('', 500, 500)
Global $buttons[2]
$buttons[0] = GUICtrlCreateButton("button 1", 0, 0, 20, 20)
$buttons[1] = GUICtrlCreateButton("button 2", 100, 100, 20, 20)
GUISetState(@SW_SHOW, $board)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case _ArraySearch($buttons, $nMsg)
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
local $result = _ArraySearch($buttons, $nMsg)
if $result <> -1 Then
ToolTip($buttons[$result])
endif
WEnd
Edited by MouseSpotter
Link to post
Share on other sites
  • Solution

Check this out

#include <Misc.au3>
#include <GUIConstants.au3>

$board = GUICreate('', 500, 500)
Global $buttons[4]
$buttons[0] = GUICtrlCreateButton("button 1", 60, 0, 70, 20)
$buttons[1] = GUICtrlCreateButton("button 2", 160, 100, 70, 20)
$buttons[2] = GUICtrlCreateButton("button 3", 160, 200, 70, 20)
$buttons[3] = GUICtrlCreateButton("button 4", 180, 300, 70, 20)
GUISetState(@SW_SHOW, $board)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_PRIMARYDOWN
$aCur = GUIGetCursorInfo()

Switch $aCur[4]

Case $buttons[0] To $buttons[3]
_drag($aCur[4], $board, $aCur)

EndSwitch

EndSwitch
WEnd

Func _drag($ControlID, $hParent, $aMpos)
$aPos = ControlGetPos($hParent, "", $ControlID)
If @error Then Return -1

$iXOffset = $aMpos[0] - $aPos[0]
$iYOffset = $aMpos[1] - $aPos[1]

While _IsPressed("01")
$aMpos = GUIGetCursorInfo()
GUICtrlSetPos($ControlID, $aMpos[0] - $iXOffset, $aMpos[1] - $iYOffset)
WEnd

EndFunc   ;==>_drag

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to post
Share on other sites

Expanded sycam0inc's script for even more fun

#include <Misc.au3>
#include <GUIConstants.au3>

Global $hGui = GUICreate('Super Simple IDE', 500, 500)
Global $aCtrlInfo[7][3] = [['Button', '!b', 0], ['Checkbox', '!c', 0], ['Combo', '!o', 0], ['Edit', '!e', 0], ['Input', '!i', 0], ['List', '!l', 0], ['Radio', '!r', 0]]
Global $aCtrls[1] = [0]
Global $aDefaultPos[4] = [396,470,90,20]

GUISetState(@SW_SHOW, $hGui)

For $i = 0 To UBound($aCtrlInfo, 1) - 1
    HotKeySet($aCtrlInfo[$i][1], '_add' & $aCtrlInfo[$i][0])
Next

While 1
    Local $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Local $sText, $sList, $aPos
            ;unset hotkeys
            For $i = 0 To UBound($aCtrlInfo, 1) - 1
                HotKeySet($aCtrlInfo[$i][1])
            Next
            ;compile list of controls
            For $i = 1 To $aCtrls[0]
                $sText = GUICtrlRead($aCtrls[$i])
                If Not StringInStr('Button|Edit|Checkbox|Combo|Input|List|Radio', $sText) Then $sText = GUICtrlRead($aCtrls[$i], 1)
                $aPos = ControlGetPos($hGui, "", $aCtrls[$i])
                $sList &= '$id' & $sText & ' = GUICtrlCreate' & StringRegExpReplace($sText, '\d+, '') & '("' & $sText & '", ' & $aPos[0] & ', ' & $aPos[1] & ', ' & $aPos[2] & ', ' & $aPos[3] & ')' & @CRLF
            Next
            MsgBox(0, '', $sList)
            Exit

        Case $GUI_EVENT_PRIMARYDOWN
            Local $aCur = GUIGetCursorInfo()
            Switch $aCur[4]
                Case $aCtrls[0] To $aCtrls[UBound($aCtrls) - 1]
                    _drag($aCur[4], $hGui, $aCur, 5, 11)
            EndSwitch

        Case $GUI_EVENT_SECONDARYDOWN
            Local $aCur = GUIGetCursorInfo()
            Switch $aCur[4]
                Case $aCtrls[0] To $aCtrls[UBound($aCtrls) - 1]
                    _resize($aCur[4], $hGui, $aCur, 2, 5)
            EndSwitch
    EndSwitch
WEnd

Func _drag($ControlID, $hParent, $aMpos, $iSnapGridX = 0, $iSnapGridY = 0)
    ;set iSnapGrid value = 1 to disable snap to grid
    If Not $iSnapGridX Then $iSnapGridX = 10
    If $iSnapGridX and Not $iSnapGridY Then $iSnapGridY = $iSnapGridX

    $aPos = ControlGetPos($hParent, "", $ControlID)
    If @error Then Return -1

    $iXOffset = $aMpos[0] - $aPos[0]
    $iYOffset = $aMpos[1] - $aPos[1]

    While _IsPressed("01")
        $aMpos = GUIGetCursorInfo()
        GUICtrlSetPos($ControlID, Round(($aMpos[0] - $iXOffset) / $iSnapGridX, 0) * $iSnapGridX, Round(($aMpos[1] - $iYOffset) / $iSnapGridY, 0) * $iSnapGridY)
    WEnd
EndFunc

Func _resize($ControlID, $hParent, $aMpos, $iSnapGridX = 0, $iSnapGridY = 0)
    If Not $iSnapGridX Then $iSnapGridX = 10
    If $iSnapGridX and Not $iSnapGridY Then $iSnapGridY = $iSnapGridX

    $aPos = ControlGetPos($hParent, "", $ControlID)
    If @error Then Return -1

    While _IsPressed("02")
        $aMpos = GUIGetCursorInfo()
        GUICtrlSetPos($ControlID, $aPos[0], $aPos[1], Round(($aMpos[0] - $aPos[0]) / $iSnapGridX, 0) * $iSnapGridX, Round(($aMpos[1] - $aPos[1]) / $iSnapGridY, 0) * $iSnapGridY)
    WEnd
EndFunc

Func _add($iType)
    $aCtrls[0] += 1
    ReDim $aCtrls[$aCtrls[0] + 1]
    $aCtrlInfo[$iType][2] += 1
    Switch $iType
        Case 0
            $aCtrls[$aCtrls[0]] = GUICtrlCreateButton($aCtrlInfo[$iType][0] & $aCtrlInfo[$iType][2], $aDefaultPos[0], $aDefaultPos[1], $aDefaultPos[2], $aDefaultPos[3])
        Case 1
            $aCtrls[$aCtrls[0]] = GUICtrlCreateCheckbox($aCtrlInfo[$iType][0] & $aCtrlInfo[$iType][2], $aDefaultPos[0], $aDefaultPos[1], $aDefaultPos[2], $aDefaultPos[3])
        Case 2
            $aCtrls[$aCtrls[0]] = GUICtrlCreateCombo($aCtrlInfo[$iType][0] & $aCtrlInfo[$iType][2], $aDefaultPos[0], $aDefaultPos[1], $aDefaultPos[2], $aDefaultPos[3])
        Case 3
            $aCtrls[$aCtrls[0]] = GUICtrlCreateEdit($aCtrlInfo[$iType][0] & $aCtrlInfo[$iType][2], $aDefaultPos[0], $aDefaultPos[1], $aDefaultPos[2], $aDefaultPos[3])
        Case 4
            $aCtrls[$aCtrls[0]] = GUICtrlCreateInput($aCtrlInfo[$iType][0] & $aCtrlInfo[$iType][2], $aDefaultPos[0], $aDefaultPos[1], $aDefaultPos[2], $aDefaultPos[3])
        Case 5
            $aCtrls[$aCtrls[0]] = GUICtrlCreateList($aCtrlInfo[$iType][0] & $aCtrlInfo[$iType][2], $aDefaultPos[0], $aDefaultPos[1], $aDefaultPos[2], $aDefaultPos[3])
        Case 6
            $aCtrls[$aCtrls[0]] = GUICtrlCreateRadio($aCtrlInfo[$iType][0] & $aCtrlInfo[$iType][2], $aDefaultPos[0], $aDefaultPos[1], $aDefaultPos[2], $aDefaultPos[3])
    EndSwitch
EndFunc

Func _addButton()
    _add(0)
EndFunc

Func _addCheckbox()
    _add(1)
EndFunc

Func _addCombo()
    _add(2)
EndFunc

Func _addEdit()
    _add(3)
EndFunc

Func _addInput()
    _add(4)
EndFunc

Func _addList()
    _add(5)
EndFunc

Func _addRadio()
    _add(6)
EndFunc
Edited by Quual
Link to post
Share on other sites

this is the project im working on it is almost done

;#GUIBuilder++.au3#==================================
;File Name.......:GUIBuilder++.au3
;Creator.........:sean.campbell7
;Created with....:Created with ISN AutoIt Studio
;Version.........:0.91 BETA
;=============================================
Opt("GUIResizeMode", 802)
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <editconstants.au3>
#Include <GuiButton.au3>
#include <array.au3>
#include <misc.au3>
#include <TabConstants.au3>
$crc = 0
Global $guihandle = "$HGUI"
$xx = 0
$au3 = ""
$codescreen = GUICreate("compiled code", 350, 350, -1, -1, $WS_CAPTION, $WS_EX_TOPMOST)
$code = GUICtrlCreateEdit("", 20, 20, 310, 240, 2048, -1)
GUICtrlSetBkColor($code, 0xFFFFFF)
$cc = GUICtrlCreateButton("Copy", 220, 280, 100, 30, -1, -1)
$ok = GUICtrlCreateButton("Ok", 120, 280, 100, 30, -1, -1)
$sc = GUICtrlCreateButton("Save as", 20, 280, 100, 30, -1, -1)
Global $ctrldata[1][8], $rdm = 1, $copyobj[7]
$toolbar = GUICreate("GUIBuilder++", @DesktopWidth -5, @DesktopWidth -300, 0, 0, 0x00010000 + 0x00020000)
$d = GUICtrlCreateButton("Date", 50, 300, 50, 50, -1, -1)
$pb = GUICtrlCreateButton("progress bar", 0, 300, 50, 50, -1, -1)
$s = GUICtrlCreateButton("slider", 50, 250, 50, 50, -1, -1)
$co = GUICtrlCreateButton("combo box", 0, 350, 50, 50, -1, -1)
$li = GUICtrlCreateButton("listbox", 50, 400, 50, 50, -1, -1)
$g = GUICtrlCreateButton("group", 0, 400, 50, 50, -1, -1)
$t = GUICtrlCreateButton("treeview", 50, 350, 50, 50, -1, -1)
$i = GUICtrlCreateButton("input", 0, 150, 50, 50, -1, -1)
$l = GUICtrlCreateButton("Lable", 50, 100, 50, 50, -1, -1)
$b = GUICtrlCreateButton("Button", 0, 100, 50, 50, -1, -1)
$c = GUICtrlCreateButton("checkbox", 50, 150, 50, 50, -1, -1)
$ic = GUICtrlCreateButton("icon", 0, 250, 50, 50, -1, -1)
$im = GUICtrlCreateButton("image", 50, 200, 50, 50, -1, -1)
$r = GUICtrlCreateButton("radiobox", 0, 200, 50, 50, -1, -1)
$e = GUICtrlCreateButton("edit", 0, 450, 50, 50)
$ca = GUICtrlCreateButton("calender", 50, 450, 50, 50)
$prop = GUICtrlCreateButton("GUI properties", 0, 50, 100, 50)
$iFile = GUICtrlCreateMenu("File")
$iFile_Export = GUICtrlCreateMenuItem('E&xport' & @TAB & 'Ctrl + E',$iFile)
GUISetState(@SW_SHOW, $toolbar)
GUISetState(@SW_MAXIMIZE, $toolbar)
Global $lao
$GUIprop = GUICreate("Gui Properties", 350, 307, -1, -1, -1, $ws_ex_topmost + $WS_EX_TOOLWINDOW)
$tab = GUICtrlCreatetab(20, 20, 310, 240, 1024, -1)
GUICtrlCreateTabItem("General")
$wintit = GUICtrlCreateInput("", 140, 110, 150, 22, -1, 512)
$hgui = GUICtrlCreateInput("HGUI", 140, 80, 150, 22, -1, 512)
GUICtrlCreateLabel("Window Title:", 40, 113, 80, 15, -1, -1)
GUICtrlSetBkColor(-1, "-2")
GUICtrlCreateLabel("Window handle:$", 40, 83, 96, 15, -1, -1)
GUICtrlSetBkColor(-1, "-2")
$guihig = GUICtrlCreateInput(0, 140, 180, 50, 20, 8192, 512)
GUICtrlCreateUpdown(-1)
$guiwid = GUICtrlCreateInput("0", 140, 150, 50, 20, 8192, 512)
GUICtrlCreateUpdown(-1)
GUICtrlCreateLabel("GUI Hight:", 40, 183, 59, 15, -1, -1)
GUICtrlSetBkColor(-1, "-2")
GUICtrlCreateLabel("Px", 200, 183, 50, 15, -1, -1)
GUICtrlSetBkColor(-1, "-2")
GUICtrlCreateLabel("GUI Width:", 40, 153, 59, 15, -1, -1)
GUICtrlSetBkColor(-1, "-2")
GUICtrlCreateLabel("Px", 200, 153, 50, 15, -1, -1)
GUICtrlSetBkColor(-1, "-2")
GUICtrlCreateTabItem("")
GUICtrlCreateLabel("GUI Colour", 40, 213, 71, 15, -1, -1)
GUICtrlSetBkColor(-1, "-2")
$colour = GUICtrlCreateInput("0xF0F0F0", 140, 210, 75, 20, -1, 512)
GUICtrlCreateButton("Colour", 220, 210, 50, 20, -1, -1)
$gcl = GUICtrlCreateButton("Cancel", 180, 270, 100, 30, -1, -1)
$gok = GUICtrlCreateButton("Ok", 80, 270, 100, 30, -1, -1)
$ctrledit = GUICreate("Control editor", 230, 400, @DesktopWidth / 4 * 3, -1, $WS_CAPTION, $WS_EX_TOPMOST)
$apply = GUICtrlCreateButton("apply", 15, 340, 100, 30)
$compile = GUICtrlCreateButton("compile", 115, 340, 100, 30)
GUICtrlCreateTab(10, 30, 210, 300, $TCS_VERTICAL)
GUICtrlCreateTabItem("General")
$xpos = GUICtrlCreateInput("", 60, 40, 40, 22, $ES_NUMBER)
GUICtrlCreateUpdown($xpos)
GUICtrlCreateLabel("X", 50, 42, 22, 22)
$ypos = GUICtrlCreateInput("", 120, 40, 40, 22, $ES_NUMBER)
GUICtrlCreateUpdown($ypos)
GUICtrlCreateLabel("Y", 110, 42, 22, 22)
$name = GUICtrlCreateInput("", 60, 100, 100, 22)
GUICtrlCreateLabel("Data", 60, 85, 50, 22)
GUICtrlCreateLabel("handle", 60, 125, 50, 22)
$handle = GUICtrlCreateInput("", 60, 144, 100, 22)
GUICtrlCreateTabItem("Apearance")
$width1 = GUICtrlCreateInput("", 60, 40, 40, 22, $ES_NUMBER)
GUICtrlCreateUpdown($width1)
$hight1 = GUICtrlCreateInput("", 120, 40, 40, 22, $ES_NUMBER)
GUICtrlCreateUpdown($hight1)
GUICtrlCreateTabItem("Style")
GUICtrlCreateTabItem("StyleEx")
GUICtrlCreateTabItem("State")
Global $key[1][2]
GUISetState(@SW_SHOW, $ctrledit)
$board = GUICreate("new window", 350, 350, -1, -1, $WS_OVERLAPPEDWINDOW, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)
$del = GUICtrlCreateDummy()
$copy = GUICtrlCreateDummy()
$paste = GUICtrlCreateDummy()
Global $keys[3][2]
$keys[0][1] = $del
$keys[0][0] = "{del}"
$keys[1][1] = $copy
$keys[1][0] = "^c"
$keys[2][1] = $paste
$keys[2][0] = "^v"
GUISetAccelerators($keys)
GUISetState(@SW_SHOW, $board)
While 1
 $cMsg = GUIGetCursorInfo($board)
 $nMsg = GUIGetMsg()
 Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $ok
   GUISetState(@SW_HIDE, $codescreen)
   GUISetState(@SW_SHOW, $board)
   $crc = 0
  Case $prop
   $oo = WinGetClientSize($board)
   GUICtrlSetData($wintit, WinGetTitle($board))
   GUICtrlSetData($guihig, $oo[1])
   GUICtrlSetData($guiwid, $oo[0])
   GUISetState(@SW_SHOW, $GUIprop)
   $xx = 1
  Case $gok
   WinMove($board, "", @DesktopWidth / 2 - GUICtrlRead($guihig) / 2, @DesktopHeight / 2 - GUICtrlRead($guiwid) / 2, GUICtrlRead($guiwid) + 16, GUICtrlRead($guihig) + 34)
   WinSetTitle($board, "", GUICtrlRead($wintit))
   $guihandle = "$" & GUICtrlRead($hgui)
   $xx = 0
   GUISetState(@SW_Hide, $GUIprop)
   GUISetState(@SW_SHOW, $board)
  Case $gcl
   GUISetState(@SW_hide, $GUIprop)
   GUISetState(@SW_SHOW, $board)
   $xx = 0
  Case $sc
   GUISetState(@SW_HIDE, $codescreen)
   GUISetState(@SW_HIDE, $board)
   GUISetState(@SW_HIDE, $ctrledit)
   $dat = FilesaveDialog("Save script", "", "Autoit 3 script files(*.au3)")
   If $dat <> "" Then
    FileWrite($dat & ".au3", $au3)
   endif
   $crc = 0
   GUISetState(@SW_SHOW, $ctrledit)
   GUISetState(@SW_SHOW, $board)
  Case $iFile_Export
   _compile(0)
   GUISetState(@SW_HIDE, $codescreen)
   GUISetState(@SW_HIDE, $board)
   GUISetState(@SW_HIDE, $ctrledit)
   $dat = FilesaveDialog("Save script", "", "Autoit 3 script files(*.au3)")
   If $dat <> "" Then
    $id = FileOpen($dat & ".au3",2)
    FileWrite($id, $au3)
   endif
   GUISetState(@SW_SHOW, $ctrledit)
   GUISetState(@SW_SHOW, $board)
  Case $cc
   ClipPut($au3)
  Case $width1, $hight1
   _itemsetsize(GUICtrlRead($width1), GUICtrlRead($hight1))
  Case $xpos, $ypos
   _itemsetpos(GUICtrlRead($xpos), GUICtrlRead($ypos))
  Case $name
   _itemsetname(GUICtrlRead($name))
  Case $apply
   _itemsetname(GUICtrlRead($name))
   _itemsetpos(GUICtrlRead($xpos), GUICtrlRead($ypos))
   _itemsetsize(GUICtrlRead($width1), GUICtrlRead($hight1))
   If GUICtrlRead($handle) <> "" Then
    For $i = 0 to UBound($ctrldata) - 1
     If $ctrldata[$i][0] = $lao and $lao <> "" Then
      $ctrldata[$i][7] = "$" & GUICtrlRead($handle)
     EndIf
    Next
   EndIf
  Case $del
   _deleteitem($lao)
  Case $copy
   _copy()
  Case $paste
   _paste()
  Case -7, -11
   If $cMsg[4] > 0 Then _guictrldrag($cMsg[4], $board)
  Case $b
   _createitem("button")
  Case $l
   _createitem("label")
  case $pb
   _createitem("progress")
  case $i
   _createitem("input")
  Case $e
   _createitem("edit")
  Case $c
   _createitem("checkbox")
  Case $r
   _createitem("radiobox")
  Case $s
   _createitem("slider")
  Case $ic
   _createitem("icon")
  case $im
   _createitem("image")
  Case $d
   _createitem("date")
  case $ca
   _createitem("calender")
  Case $co
   _createitem("combo")
  Case $li
   _createitem("listbox")
  case $t
   _createitem("tree")
  Case $g
   _createitem("group")
  Case $compile
   _compile()
  Case $GUI_EVENT_MINIMIZE
   GUISetState(@SW_HIDE, $board)
   GUISetState(@SW_HIDE, $ctrledit)
   GUISetState(@SW_HIDE, $codescreen)
   GUISetState(@SW_HIDE, $GUIprop)
  Case $GUI_EVENT_RESTORE
   GUISetState(@SW_show, $ctrledit)
   GUISetState(@SW_Show, $board)
   If $crc Then GUISetState(@SW_SHOW, $codescreen)
   If $xx Then GUISetState(@SW_SHOW, $GUIprop)
 EndSwitch
 WinSetOnTop($ctrledit, "", 1)
WEnd
Func _guictrldrag($control, $hgui)
 $cbutton = $control
 $lao = $control
 $cInfo = GUIGetCursorInfo($hGUI)
 $aPos = ControlGetPos($hGUI, "", $cButton)
 $iSubtractX = $cInfo[0] - $aPos[0]
 $iSubtractY = $cInfo[1] - $aPos[1]
 Sleep(200)
 $cInfo = GUIGetCursorInfo($hGUI)
 If $cInfo[2] = 1 Then
  $cInfo = GUIGetCursorInfo($hGUI)
  If $cInfo[4] = $cButton Then
   Do
    $cInfo = GUIGetCursorInfo($hGUI)
    ControlMove($hGUI, "", $cButton, $cInfo[0] - $iSubtractX, $cInfo[1] - $iSubtractY)
    For $i = 0 to UBound($ctrldata) - 1
     If $ctrldata[$i][0] = $control and $control <> "" Then
      $ctrldata[$i][1] = $cInfo[0] - $iSubtractX
      $ctrldata[$i][2] = $cInfo[1] - $iSubtracty
     EndIf
    Next
    For $i = 0 to UBound($ctrldata) - 1
     If $ctrldata[$i][0] = $lao and $lao <> "" Then
      GUICtrlSetData($xpos, $ctrldata[$i][1])
      GUICtrlSetData($ypos, $ctrldata[$i][2])
      GUICtrlSetData($width1, $ctrldata[$i][3])
      GUICtrlSetData($hight1, $ctrldata[$i][4])
      GUICtrlSetData($name, $ctrldata[$i][5])
      GUICtrlSetData($handle, StringTrimLeft($ctrldata[$i][7], 1))
     EndIf
    next
   Until Not $cInfo[2]
  EndIf
 Else
  return 0
 EndIf
 Do
 Until GUIGetMsg() = 0
 _itemsetpos(_round($cInfo[0] - $iSubtractX), _round($cInfo[1] - $iSubtractY))
EndFunc
Func _createitem($type, $x = 0, $y = 0, $width = -1, $hight = -1)
 $rdm += 1
 Switch $type
  Case "button"
   If $width = -1 then $width = 50
   If $hight = -1 then $hight = 30
   $ct = GUICtrlCreateButton("my text", $x, $y, $width, $hight)
   ReDim $ctrldata[$rdm + 1][8]
   $ctrldata[$rdm][0] = $ct
   $ctrldata[$rdm][1] = $x
   $ctrldata[$rdm][2] = $y
   $ctrldata[$rdm][3] = $width
   $ctrldata[$rdm][4] = $hight
   $ctrldata[$rdm][5] = "my text"
  Case "label"
   If $width = -1 then $width = 100
   If $hight = -1 then $hight = 20
   $ct = GUICtrlCreateLabel("my text", $x, $y, $width, $hight)
   ReDim $ctrldata[$rdm + 1][8]
   $ctrldata[$rdm][0] = $ct
   $ctrldata[$rdm][1] = $x
   $ctrldata[$rdm][2] = $y
   $ctrldata[$rdm][3] = $width
   $ctrldata[$rdm][4] = $hight
   $ctrldata[$rdm][5] = "my text"
  Case "input"
   If $width = -1 then $width = 100
   If $hight = -1 then $hight = 20
   $ct = GUICtrlCreateinput("my text", $x, $y, $width, $hight)
   ReDim $ctrldata[$rdm + 1][8]
   $ctrldata[$rdm][0] = $ct
   $ctrldata[$rdm][1] = $x
   $ctrldata[$rdm][2] = $y
   $ctrldata[$rdm][3] = $width
   $ctrldata[$rdm][4] = $hight
   $ctrldata[$rdm][5] = "my text"
  Case "Edit"
   If $width = -1 then $width = 150
   If $hight = -1 then $hight = 150
   $ct = GUICtrlCreateEdit("my text", $x, $y, $width, $hight)
   ReDim $ctrldata[$rdm + 1][8]
   $ctrldata[$rdm][0] = $ct
   $ctrldata[$rdm][1] = $x
   $ctrldata[$rdm][2] = $y
   $ctrldata[$rdm][3] = $width
   $ctrldata[$rdm][4] = $hight
   $ctrldata[$rdm][5] = "my text"
  Case "progress"
   If $width = -1 then $width = 100
   If $hight = -1 then $hight = 20
   $ct = GUICtrlCreateProgress($x, $y, $width, $hight)
   GUICtrlSetData(-1, 50)
   ReDim $ctrldata[$rdm + 1][8]
   $ctrldata[$rdm][0] = $ct
   $ctrldata[$rdm][1] = $x
   $ctrldata[$rdm][2] = $y
   $ctrldata[$rdm][3] = $width
   $ctrldata[$rdm][4] = $hight
   $ctrldata[$rdm][5] = 50
  Case "checkbox"
   If $width = -1 then $width = 50
   If $hight = -1 then $hight = 20
   $ct = GUICtrlCreateCheckbox("my text", $x, $y, $width, $hight)
   ReDim $ctrldata[$rdm + 1][8]
   $ctrldata[$rdm][0] = $ct
   $ctrldata[$rdm][1] = $x
   $ctrldata[$rdm][2] = $y
   $ctrldata[$rdm][3] = $width
   $ctrldata[$rdm][4] = $hight
   $ctrldata[$rdm][5] = "my text"
  Case "radiobox"
   If $width = -1 then $width = 50
   If $hight = -1 then $hight = 20
   $ct = GUICtrlCreateRadio("my text", $x, $y, $width, $hight)
   ReDim $ctrldata[$rdm + 1][8]
   $ctrldata[$rdm][0] = $ct
   $ctrldata[$rdm][1] = $x
   $ctrldata[$rdm][2] = $y
   $ctrldata[$rdm][3] = $width
   $ctrldata[$rdm][4] = $hight
   $ctrldata[$rdm][5] = "my text"
  Case "slider"
   If $width = -1 then $width = 150
   If $hight = -1 then $hight = 20
   $ct = GUICtrlCreateSlider($x, $y, $width, $hight)
   ReDim $ctrldata[$rdm + 1][8]
   $ctrldata[$rdm][0] = $ct
   $ctrldata[$rdm][1] = $x
   $ctrldata[$rdm][2] = $y
   $ctrldata[$rdm][3] = $width
   $ctrldata[$rdm][4] = $hight
   $ctrldata[$rdm][5] = 0
  Case "icon"
   If $width = -1 then $width = 50
   If $hight = -1 then $hight = 50
   $ct = GUICtrlCreateIcon(@scriptdir & "\dummy.ico", -1, $x, $y, $width, $hight)
   ReDim $ctrldata[$rdm + 1][8]
   $ctrldata[$rdm][0] = $ct
   $ctrldata[$rdm][1] = $x
   $ctrldata[$rdm][2] = $y
   $ctrldata[$rdm][3] = $width
   $ctrldata[$rdm][4] = $hight
   $ctrldata[$rdm][5] = "my text"
  Case "image"
   If $width = -1 then $width = 50
   If $hight = -1 then $hight = 50
   $ct = GUICtrlCreatePic(@scriptdir & "\dummy.bmp", $x, $y, $width, $hight)
   ReDim $ctrldata[$rdm + 1][8]
   $ctrldata[$rdm][0] = $ct
   $ctrldata[$rdm][1] = $x
   $ctrldata[$rdm][2] = $y
   $ctrldata[$rdm][3] = $width
   $ctrldata[$rdm][4] = $hight
   $ctrldata[$rdm][5] = ""
  Case "date"
   If $width = -1 then $width = 150
   If $hight = -1 then $hight = 20
   $ct = GUICtrlCreateDate("", $x, $y, $width, $hight)
   ReDim $ctrldata[$rdm + 1][8]
   $ctrldata[$rdm][0] = $ct
   $ctrldata[$rdm][1] = $x
   $ctrldata[$rdm][2] = $y
   $ctrldata[$rdm][3] = $width
   $ctrldata[$rdm][4] = $hight
   $ctrldata[$rdm][5] = ""
  Case "calender"
   If $width = -1 then $width = 180
   If $hight = -1 then $hight = 164
   $ct = GUICtrlCreateMonthCal("", $x, $y, $width, $hight)
   ReDim $ctrldata[$rdm + 1][8]
   $ctrldata[$rdm][0] = $ct
   $ctrldata[$rdm][1] = $x
   $ctrldata[$rdm][2] = $y
   $ctrldata[$rdm][3] = $width
   $ctrldata[$rdm][4] = $hight
   $ctrldata[$rdm][5] = ""
  Case "combo"
   If $width = -1 then $width = 50
   If $hight = -1 then $hight = 30
   $ct = GUICtrlCreateCombo("my text", $x, $y, $width, $hight)
   GUICtrlSetData(-1, "item1|item2|item3", "item1")
   ReDim $ctrldata[$rdm + 1][8]
   $ctrldata[$rdm][0] = $ct
   $ctrldata[$rdm][1] = $x
   $ctrldata[$rdm][2] = $y
   $ctrldata[$rdm][3] = $width
   $ctrldata[$rdm][4] = $hight
   $ctrldata[$rdm][5] = "item1|item2|item3"
  Case "listbox"
   If $width = -1 then $width = 150
   If $hight = -1 then $hight = 150
   $ct = GUICtrlCreatelist("my text", $x, $y, $width, $hight)
   ReDim $ctrldata[$rdm + 1][8]
   $ctrldata[$rdm][0] = $ct
   $ctrldata[$rdm][1] = $x
   $ctrldata[$rdm][2] = $y
   $ctrldata[$rdm][3] = $width
   $ctrldata[$rdm][4] = $hight
   $ctrldata[$rdm][5] = "my text"
  Case "tree"
   If $width = -1 then $width = 150
   If $hight = -1 then $hight = 150
   $ct = GUICtrlCreateTreeView("my text", $x, $y, $width, $hight)
   $td = GUICtrlCreateTreeViewItem("my text", $ct)
   GUICtrlCreateTreeViewItem("sub", $td)
   ReDim $ctrldata[$rdm + 1][8]
   $ctrldata[$rdm][0] = $ct
   $ctrldata[$rdm][1] = $x
   $ctrldata[$rdm][2] = $y
   $ctrldata[$rdm][3] = $width
   $ctrldata[$rdm][4] = $hight
   $ctrldata[$rdm][5] = "my text"
  Case "group"
   If $width = -1 then $width = 150
   If $hight = -1 then $hight = 150
   $ct = GUICtrlCreateGroup("my text", $x, $y, $width, $hight)
   ReDim $ctrldata[$rdm + 1][8]
   $ctrldata[$rdm][0] = $ct
   $ctrldata[$rdm][1] = $x
   $ctrldata[$rdm][2] = $y
   $ctrldata[$rdm][3] = $width
   $ctrldata[$rdm][4] = $hight
   $ctrldata[$rdm][5] = "my text"
 EndSwitch
 GUICtrlSetCursor($ct, 9)
 $ctrldata[$rdm][6] = $type
 $ctrldata[$rdm][7] = "$" & $type & $rdm - 1
 $lao = $ct
 For $i = 0 to UBound($ctrldata) - 1
  If $ctrldata[$i][0] = $lao and $lao <> "" Then
   GUICtrlSetData($xpos, $ctrldata[$i][1])
   GUICtrlSetData($name, $ctrldata[$i][5])
   GUICtrlSetData($width1, $ctrldata[$i][3])
   GUICtrlSetData($hight1, $ctrldata[$i][4])
   GUICtrlSetData($ypos, $ctrldata[$i][2])
   GUICtrlSetData($handle, StringTrimLeft($ctrldata[$i][7], 1))
  EndIf
 Next
 ControlFocus($board, "", GUICtrlGetHandle($ct))
EndFunc
Func _deleteitem($item)
 GUICtrlDelete($item)
 For $i = 0 to UBound($ctrldata) - 1
  If $ctrldata[$i][0] = $item and $item <> "" Then
   _ArrayDelete($ctrldata, $i)
   $lao = $ctrldata[$i - 1][0]
   GUICtrlSetData($xpos, $ctrldata[$i - 1][1])
   GUICtrlSetData($name, $ctrldata[$i - 1][5])
   GUICtrlSetData($width1, $ctrldata[$i - 1][3])
   GUICtrlSetData($hight1, $ctrldata[$i - 1][4])
   GUICtrlSetData($ypos, $ctrldata[$i - 1][2])
   GUICtrlSetData($handle, StringTrimLeft($ctrldata[$i - 1][7], 1))
  EndIf
 Next
 ControlFocus($board, "", $item)
EndFunc
Func _itemsetpos($x, $y, $item = $lao)
 GUICtrlSetPos($item, $x, $y)
 for $i = 0 to UBound($ctrldata) - 1
  If $ctrldata[$i][0] = $item and $item <> "" Then
   $ctrldata[$i][1] = $x
   $ctrldata[$i][2] = $y
   GUICtrlSetData($xpos, $ctrldata[$i][1])
   GUICtrlSetData($ypos, $ctrldata[$i][2])
  EndIf
 Next
EndFunc
Func _itemsetname($name, $item = $lao)
 GUICtrlSetdata($item, $name)
 for $i = 0 to UBound($ctrldata) - 1
  If $ctrldata[$i][0] = $item and $item <> "" Then
   $ctrldata[$i][5] = $name
  EndIf
 Next
EndFunc
Func _itemsetsize($x, $y, $item = $lao)
 for $i = 0 to UBound($ctrldata) - 1
  If $ctrldata[$i][0] = $item and $item <> "" Then
   $ctrldata[$i][3] = $x
   $ctrldata[$i][4] = $y
   GUICtrlSetPos($item, $ctrldata[$i][1], $ctrldata[$i][2], $x, $y)
  EndIf
 Next
EndFunc
Func _round($number)
 If $number < 0 then Return 0
 Global $n = $Number
 $ilen = StringLen($n)
 if StringTrimLeft($n, $ilen - 1) = 5 or StringTrimleft($n, $ilen - 1) = 0 Then Return $n
 if StringTrimLeft($n, $ilen - 1) > 5 Then
  Do
   $ilen = StringLen($n)
   if StringTrimLeft($n, $ilen - 1) <= 7 Then ;so that 7 will become 5 not 10
    $n -= 1
   ElseIf StringTrimLeft($n, $ilen - 1) >= 7 Then
    $n += 1
   EndIf
   $ilen = StringLen($n)
  Until StringTrimLeft($n, $ilen - 1) = 5 or StringTrimleft($n, $ilen - 1) = 0
 Else
  Do
   $ilen = StringLen($n)
   if StringTrimLeft($n, $ilen - 1) < 3 Then ;so that 3 will become 5 not 0
    $n -= 1
   ElseIf StringTrimLeft($n, $ilen - 1) >= 3 Then
    $n += 1
   EndIf
   $ilen = StringLen($n)
  Until StringTrimLeft($n, $ilen - 1) = 5 or StringTrimleft($n, $ilen - 1) = 0
 EndIf
 Return $n
EndFunc
Func _copy($item = $lao)
 For $i = 0 to UBound($ctrldata) - 1
  If $ctrldata[$i][0] = $item and $item <> "" Then
   $copyobj[1] = $ctrldata[$i][1]
   $copyobj[2] = $ctrldata[$i][2]
   $copyobj[3] = $ctrldata[$i][3]
   $copyobj[4] = $ctrldata[$i][4]
   $copyobj[5] = $ctrldata[$i][5]
   $copyobj[6] = $ctrldata[$i][6]
  EndIf
 Next
EndFunc
Func _paste()
 If $copyobj[1] <> "" Then
  _createitem($copyobj[6], _round($cMsg[0]), _round($cMsg[1]), $copyobj[3], $copyobj[4])
  _itemsetname($copyobj[5])
  GUICtrlSetData($name, $copyobj[5])
 EndIf
EndFunc
Func _compile($iflag=1)
 Global $au3 = ";created with guibuilder++" & @crlf & "#include <GUIConstantsEx.au3>" & @CRLF & "#include <WindowsConstants.au3>" & @CRLF
 $size = WinGetClientSize($board)
 $au3 &= $guihandle & " = GUICreate('" & WinGetTitle($board) & "'," & $size[0] & "," & $size[1] & ")" & @CRLF
 For $i = 0 To UBound($ctrldata) - 1
  Switch $ctrldata[$i][6]
   Case "button"
    $au3 &= $ctrldata[$i][7] & " = GUICtrlCreateButton('" & $ctrldata[$i][5] & "'," & $ctrldata[$i][1] & "," & $ctrldata[$i][2] & "," & $ctrldata[$i][3] & "," & $ctrldata[$i][4] & ")" & @crlf
   Case "label"
    $au3 &= $ctrldata[$i][7] & " = GUICtrlCreateLabel('" & $ctrldata[$i][5] & "'," & $ctrldata[$i][1] & "," & $ctrldata[$i][2] & "," & $ctrldata[$i][3] & "," & $ctrldata[$i][4] & ")" & @crlf
   Case "input"
    $au3 &= $ctrldata[$i][7] & " = GUICtrlCreateInput('" & $ctrldata[$i][5] & "'," & $ctrldata[$i][1] & "," & $ctrldata[$i][2] & "," & $ctrldata[$i][3] & "," & $ctrldata[$i][4] & ")" & @crlf
   Case "Edit"
    $au3 &= $ctrldata[$i][7] & " = GUICtrlCreateEdit('" & $ctrldata[$i][5] & "'," & $ctrldata[$i][1] & "," & $ctrldata[$i][2] & "," & $ctrldata[$i][3] & "," & $ctrldata[$i][4] & ")" & @crlf
   Case "progress"
    $au3 &= $ctrldata[$i][7] & " = GUICtrlCreateProgress('" & $ctrldata[$i][5] & "'," & $ctrldata[$i][1] & "," & $ctrldata[$i][2] & "," & $ctrldata[$i][3] & "," & $ctrldata[$i][4] & ")" & @crlf
   Case "checkbox"
    $au3 &= $ctrldata[$i][7] & " = GUICtrlCreateCheckbox('jmn" & $ctrldata[$i][5] & "'," & $ctrldata[$i][1] & "," & $ctrldata[$i][2] & "," & $ctrldata[$i][3] & "," & $ctrldata[$i][4] & ")" & @crlf
   Case "radiobox"
    $au3 &= $ctrldata[$i][7] & " = GUICtrlCreateRadio('" & $ctrldata[$i][5] & "'," & $ctrldata[$i][1] & "," & $ctrldata[$i][2] & "," & $ctrldata[$i][3] & "," & $ctrldata[$i][4] & ")" & @crlf
   Case "slider"
    $au3 &= $ctrldata[$i][7] & " = GUICtrlCreateSlider('" & $ctrldata[$i][1] & "'," & $ctrldata[$i][2] & "," & $ctrldata[$i][3] & "," & $ctrldata[$i][4] & ")" & @crlf & "guictrlsetdata(-1," & $ctrldata[$i][5] & ")" & @crlf
   Case "icon"
    $au3 &= $ctrldata[$i][7] & " = GUICtrlCreateIcon('" & $ctrldata[$i][5] & "',-1," & $ctrldata[$i][1] & "," & $ctrldata[$i][2] & "," & $ctrldata[$i][3] & "," & $ctrldata[$i][4] & ")" & @crlf
   Case "image"
    $au3 &= $ctrldata[$i][7] & " = GUICtrlCreatePic('" & $ctrldata[$i][5] & "'," & $ctrldata[$i][1] & "," & $ctrldata[$i][2] & "," & $ctrldata[$i][3] & "," & $ctrldata[$i][4] & ")" & @crlf
   Case "date"
    $au3 &= $ctrldata[$i][7] & " = GUICtrlCreateDate('" & $ctrldata[$i][5] & "'," & $ctrldata[$i][1] & "," & $ctrldata[$i][2] & "," & $ctrldata[$i][3] & "," & $ctrldata[$i][4] & ")" & @crlf
   Case "calender"
    $au3 &= $ctrldata[$i][7] & " = GUICtrlCreateMonthCal('" & $ctrldata[$i][5] & "'," & $ctrldata[$i][1] & "," & $ctrldata[$i][2] & "," & $ctrldata[$i][3] & "," & $ctrldata[$i][4] & ")" & @crlf
   Case "combo"
    $au3 &= $ctrldata[$i][7] & " = GUICtrlCreateCombo('" & $ctrldata[$i][5] & "'," & $ctrldata[$i][1] & "," & $ctrldata[$i][2] & "," & $ctrldata[$i][3] & "," & $ctrldata[$i][4] & ")" & @crlf
   Case "listbox"
    $au3 &= $ctrldata[$i][7] & " = GUICtrlCreateList('" & $ctrldata[$i][5] & "'," & $ctrldata[$i][1] & "," & $ctrldata[$i][2] & "," & $ctrldata[$i][3] & "," & $ctrldata[$i][4] & ")" & @crlf
   Case "tree"
    $au3 &= $ctrldata[$i][7] & " = GUICtrlCreateTreeView('" & $ctrldata[$i][5] & "'," & $ctrldata[$i][1] & "," & $ctrldata[$i][2] & "," & $ctrldata[$i][3] & "," & $ctrldata[$i][4] & ")" & @crlf
   Case "group"
    $au3 &= $ctrldata[$i][7] & " = GUICtrlCreateGroup('" & $ctrldata[$i][5] & "'," & $ctrldata[$i][1] & "," & $ctrldata[$i][2] & "," & $ctrldata[$i][3] & "," & $ctrldata[$i][4] & ")" & @crlf
  EndSwitch
 next
 $au3 &= "GUISetState()" & @CRLF & "while 1" & @CRLF & @TAB & "Switch GUIGetMsg()" & @CRLF & @TAB & @TAB & "Case -3" & @CRLF & @TAB & "Exit" & @crlf & @TAB & "EndSwitch" & @CRLF & "WEnd"
 if $iflag Then
 GUICtrlSetData($code, $au3)
 GUISetState(@SW_SHOW, $codescreen)
 EndIf
EndFunc

All my projects live on github

Link to post
Share on other sites

you can make use of a For Next loop with control names rather than such a long Switch Statement.

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...