Sign in to follow this  
Followers 0
Ascend4nt

_GUIBox - Rubberband selection boxes using GUIs

4 posts in this topic

#1 ·  Posted (edited)

_GUIBox

Rubberband selection boxes using GUIs

Posted Image

Create Rectangles using GUI boxes. Great for Rubber-band selection (as an alternative to DrawFocusRect), or just putting box outlines on the screen period!

Example code included (including rubber-band style box-selection simulation).

#include <_GUIBox.au3>
; ===============================================================================================================================
; <TestGUIBox.au3>
;
;   Tests for _GUIBox UDF.
;
; Author: Ascend4nt
; ===============================================================================================================================

; ===================================================================================================================
; GLOBAL VARIABLES
; ===================================================================================================================

Global $bEscPressed=False,$bHomeKeyPressed=False,$bEndKeyPressed=False,$aHomeLoc[2]=[-1,-1]

; ===================================================================================================================
; HOTKEY FUNCTIONS
; ===================================================================================================================

Func _EscHotKeyPressed()
    $bEscPressed=True
EndFunc

Func _HomeKeyPressed()
    If Not $bHomeKeyPressed Then
        $bHomeKeyPressed=True
        $aHomeLoc=MouseGetPos()
    EndIf
EndFunc

Func _EndKeyPressed()
    If $bHomeKeyPressed Then $bEndKeyPressed=True
EndFunc

; ===================================================================================================================
; MAIN START
; ===================================================================================================================

Test1()
Test2()

; Test 1
Func Test1()
    MsgBox(0,"Rubber-Band Box Example","After Clicking OK, the Rubber-Band GUI-Box Example will start."&@CRLF& _
        "Press [Home] to set the initial Box start, and then [End] to set the end location of the box."&@CRLF& _
        "You may stop the routine at any time by pressing [Escape].")

    HotKeySet("{ESC}","_EscHotKeyPressed")

    Dim $aCurMousePos,$aRubberBandGBox

    $aRubberBandGBox=_GBoxCreate("",3,0xFF0000)
    HotKeySet("{HOME}","_HomeKeyPressed")
    HotKeySet("{END}","_EndKeyPressed")

    While Not $bEscPressed And Not $bEndKeyPressed
        If $bHomeKeyPressed Then
            $aCurMousePos=MouseGetPos()
            _GBoxShowAt($aRubberBandGBox,$aHomeLoc[0],$aHomeLoc[1],$aCurMousePos[0],$aCurMousePos[1])
        EndIf
        Sleep(5)
    WEnd
    If $bHomeKeyPressed And IsArray($aCurMousePos) Then
        MsgBox(0,"Rubber-band box example complete","Last coordinates of the Rubber-band box: "& _
            "X1:"&$aHomeLoc[0]&" Y1:"&$aHomeLoc[1]&" X2:"&$aCurMousePos[0]&" Y2:"&$aCurMousePos[1])
    EndIf
    _GBoxDestroy($aRubberBandGBox)
EndFunc

; Test 2
Func Test2()
    Local $aBugaBox,$aBoxRed,$aBoxGreen,$aBoxBlue,$aBoxFADED

    $aBugaBox=_GBoxCreate()
    $aBoxRed=_GBoxCreate("",5,0XFF0000)
    $aBoxGreen=_GBoxCreate("",1,0xFF00)
    $aBoxBlue=_GBoxCreate("",1,0xFF)
    $aBoxFADED=_GBoxCreate("",1,0x0FADED)

    MsgBox(0,"Test 2 - Multiple GUI Boxes","Ready to show boxes - Click OK")

    _GBoxShowAt($aBugaBox,100,100,800,800)
    _GBoxShowAt($aBoxRed,300,400,700,700)
    _GBoxShowAt($aBoxGreen,400,800,402,802)
    _GBoxShowAt($aBoxBlue,801,200,900,900)
    _GBoxShowAt($aBoxFADED,410,410,790,790)

    MsgBox(0,"Now to Hide them","Click OK to Hide the boxes now")

    _GBoxHide($aBugaBox)
    _GBoxHide($aBoxRed)
    _GBoxHide($aBoxGreen)
    _GBoxHide($aBoxBlue)
    _GBoxHide($aBoxFADED)

    MsgBox(0,"Now to Redisplay Them","Click OK to Re-display the boxes, though one will have a new color, transparency, and thickness")

    _GBoxSetDisplayProps($aBugaBox,3,0x0899CC,255)  ; Changing the thickness, color, and transparency (to non-transparent)
    ; Since the box was invisible, we need to force it to recognize a resize (last parameter=True) as we altered the thickness
    ;   If we had instead put _GboxShow($aBugaBox) prior to _GBoxSetDisplayProps(), we would not need to force a resize
    _GBoxShow($aBugaBox,False,True)
    _GBoxShow($aBoxRed)
    _GBoxShow($aBoxGreen)
    _GBoxShow($aBoxBlue)
    _GBoxShow($aBoxFADED)

    MsgBox(0,"That's all folks!","Now click OK to delete")

    _GBoxDestroy($aBugaBox)
    _GBoxDestroy($aBoxRed)
    _GBoxDestroy($aBoxGreen)
    _GBoxDestroy($aBoxBlue)
    _GBoxDestroy($aBoxFADED)
EndFunc

Download the ZIP from my site

Ascend4nt's AutoIT Code License agreement:

While I provide this source code freely, if you do use the code in your projects, all I ask is that:

  • If you provide source, keep the header as I have put it, OR, if you expand it, then at least acknowledge me as the original author, and any other authors I credit
  • If the program is released, acknowledge me in your credits (it doesn't have to state which functions came from me, though again if the source is provided - see #1)
  • The source on it's own (as opposed to part of a project) can not be posted unless a link to the page(s) where the code were retrieved from is provided and a message stating that the latest updates will be available on the page(s) linked to.
  • Pieces of the code can however be discussed on the threads where Ascend4nt has posted the code without worrying about further linking.
*edit: clarified with the word 'outlines' so as not to confuse people. (creating resizable solid boxes is a much simpler task not even needing a UDF - I just posted code to do exactly this -> ) Edited by Ascend4nt

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Such a great script. However, I see in the source file that $iGBoxColor = background color but in fact, it's the border color of the box not the background one. So can you add an option to set the background color of the box and its transparency as well? Thanks Edited by Bot

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Such a great script. However, I see in the source file that $iGBoxColor = background color but in fact, it's the border color of the box not the background one. So can you add an option to set the background color of the box and its transparency as well? Thanks

Are you kidding? What do you suppose this line does?:

GUISetBkColor($iGBoxColor,$aBoxRet[$i])

The GUI's are created *without* borders, so I don't know where you get the idea that there even is one.

*edit: Bot, I think you misunderstood - if you are looking to create full boxes (not outlines like my code creates), then you've got a much simpler task. I clarified the wording in my first post, hopefully that should make it more clear. The 'outline' created by my code is actually 4 separate GUI's.

Edited by Ascend4nt

Share this post


Link to post
Share on other sites

Are you kidding? What do you suppose this line does?:

GUISetBkColor($iGBoxColor,$aBoxRet[$i])

The GUI's are created *without* borders, so I don't know where you get the idea that there even is one.

*edit: Bot, I think you misunderstood - if you are looking to create full boxes (not outlines like my code creates), then you've got a much simpler task. I clarified the wording in my first post, hopefully that should make it more clear. The 'outline' created by my code is actually 4 separate GUI's.

OK I see. Then I will create a full box. Thanks for your answer :mellow:

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

  • Similar Content

    • Katie_Deely
      By Katie_Deely
      Hey
       
      I have a GUI with an edit-field and a button.
      First I write some text into the edit-field and select a part of it. After that I press the button, and the selection is edited.
      How would I do that, though? When the text is selected and I press the button, it's unselected before the button actually raises an event. 
    • Joep86
      By Joep86
      Hi, 
      I just started recently with AutoIT and I am trying to make two dropdownlists where the selectable values of the second dropdownlist will be depending on what is selected on the first one.
      For example: 
      Dropdown 1                 Dropdown 2                   
      xxx                =>             01-15    ("01" , "02" ,"03" , ...)                    
      yyy                =>             a - f       ("a" , "b" ,"c" ,"d" ,"e" ,"f" ) 
      zzz                =>             "new", "old", "spare"
       
      I started with this code that I've found in this Forum:
      #include <GUIConstantsEx.au3>
      ; Here is the array
      Global $aArray[6] = ["SORT", "PCM", "UNIF", "KKE", "GMS", "CDY"]
      ; And here we get the elements into a list
      $sList = ""
      For $i = 0 To UBound($aArray) - 1
          $sList &= "|" & $aArray[$i]
      Next
      ; Create a GUI
      #include <GUIConstantsEx.au3>
      $hGUI = GUICreate("DropDown", 500, 500)
      ; Create the combo
      $hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
      ; And fill it
      GUICtrlSetData($hCombo, $sList)
      GUISetState()
      While 1
          Switch GUIGetMsg()
              Case $GUI_EVENT_CLOSE
                  Exit
          EndSwitch
       WEnd
       
       
      Any idea how to start on this one...
      thanks upfront
       
       
       
    • UEZ
      By UEZ
      I'm stuck on how to use for range selection .Cells function.
      Instead of
      _Excel_RangeSort($oWorkbook, Default, Default, "AD:AD", Default, Default, $xlYes, False, Default, "AE:AE", Default, "L:L", Default) and
      $aResult = _Excel_RangeRead($oWorkbook, 1, "S2:AB" & $iRows) which works properly I want to use Cells to select the range.
       
      Why? Because the Excel sheet was modified and an additional row was inserted. I want to create the script more dynamically by selection it with Cells because I can search for the column headers.
      Any idea?
       
      Thanks.
    • Xandy
      By Xandy
      Hi I'm struggling to clear the display text of of a GUI control combo selection string.
      I would like to clear the selection like it is clear after it is populated, but not remove any items from the list.

      Here is a small example.

      #include <GuiComboBox.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> ; Create GUI $hgui= guicreate("Clear ComboBox Edit Text", 320, 200) $control_combo= guictrlcreatecombo("", 10, 10, 250, 20, $CBS_DROPDOWNLIST) $control_clear_button= guictrlcreatebutton("Reset Blank Combo Selection String", 10, 40, 200, 20) guisetstate() guictrlsetdata($control_combo, "a|b|c"); Populate Combo while 1 switch guigetmsg() case $control_clear_button guictrlsetdata($control_combo, ""); This clears the entire list frustrating me case $gui_event_close exitloop endswitch;guigetmsg() wend;main loopDoes anyone one know how I can reset the selection to "", clear, empty set?I've tried SetEditText but doesn't work CBS_DROPDOWNLIST.

      SOLVED:
      Sorry I thought I had tried this: _GUICtrlComboBox_SetCurSel($control_combo, -1) is the solution.
    • javip
      By javip
      so my script was made to load drivers based on a selection from a combo box. i've created a VERY robust system to load drivers when imaging with wds or ghost using a winPE wim. WDS does not work correctly with injected drivers. so comes into play my script/program that loads from a winPE wim after wds loads. anyone knows WDS is pretty powerful but it does not always have proper drivers once the winPE loads. so my program loads drivers into winPE based on the model / device. so if we get a new model of laptop or desktop and we want to save up that image to wds we find 32bit drivers and we load them into my program.
      wds then in turn loads my winPE with my program set to autolaunch and presenting all these options. if winPE contained a generic driver then all is good. if not then we go through my list and usually one of the drivers does work but in case it doesn't we add to my list.
      that's just the pre-amble incase anyone asks what i'm doing.
      reminder that this has worked flawlessly for the better part of a year. but now with more devices it's getting cumbersome to manually edit my code, then compile, then mount edit and recompile the winPE wim and inject my autoit program into it.
      takes a maximum of 5 minutes but when you're constantly testing it gets VERY bad.
       
      here's a snippet of the array for the combobox.
      Local $aList[300][2] = [["___________", "___________"], _         ["ASUS", "ASUS"], _         ["HP Probook 4430s", "HP Probook 4430s"], _         ["Lenovo S10-3", "Lenovo S10-3"], _         ["Lenovo x200/x230", "Lenovo x200/x230"], _ so this populates a combo box that lists these entries.
      i use a case select to determine which box was selected. very manual editing when i need to add another device.
      Func selection()     $sSel = GUICtrlRead($cb_platform)     $iIndex = _ArraySearch($aList, $sSel)     Select         Case $iIndex = 1 ;~ ASUS             $driver = (@scriptdir & "\drivers\hp32\Netrtl32.inf")             $nothing = $option         Case $iIndex = 2 ;~ HP Probook 4430s             $driver = (@scriptdir & "\drivers\hp4430\hp86win7.inf")             $nothing = $option         Case $iIndex = 3 ;~ Lenovo S10-3             $driver = (@scriptdir & "\drivers\lenovos103\Netrtl32.inf")             $nothing = $option EndFunc this is the part of the script which i'm trying to revamp. right now my script works very awesome for what we're doing. however i want it more streamlined.
      as you can see once a combobox selection is selected, then it goes to that CASE and populates those variables then it kicks down to a function that i have that continues either ghost or wds depending on a selected radio box.
      this is what i have now for the array for the combobox.
      $drivers_folder=_FileListToArray(@scriptdir & "\drivers\","*",2) $cb_platform = GUICtrlCreateCombo("",10,40,600,120,-1,-1) For $i=1 To Ubound($drivers_folder)-1     GUICtrlSetData($cb_platform,$drivers_folder[$i]) Next this populates the combox based on the folder i have with each individual device. instead of creating a long winded array.
      the problem i have now is i don't know how to make it load the driver within that folder without a case select.
      i was thinking maybe something that got the name of the folder selected, then appended a "*.inf" at the end to load. but i'm totally in the dark of how to do this.
      if you'd like me to post all my code to help, please let me know.