Jump to content

GUICreateHolesByArray - Create more then one square hole in GUI


Guest
 Share

Recommended Posts

Hello,

Some time ago I wanted to create more more then one hole in GUI.
I found examples here how to create hole but the problem is that if you want to create more then one, then it is more
complicated.
So I made function that deal with this complexity and make it simple.
I decided to share it.

Screenshot_4.png.62c6822825074b38f160a7b

 

Code:

#include <WindowsConstants.au3>
#include <ColorConstantS.au3>
#include <WinAPI.au3>
#include <Array.au3>

#AutoIt3Wrapper_Run_AU3Check=n


#Region High-Level Code: Example

    ; Click Exit to exit the example
    HotKeySet('{ESC}','Exit1')
    Func Exit1()
        Exit
    EndFunc

    ; Create the GUI
    Global Const $hGUI_x_size = 415,$hGUI_y_size = 440
    $hGUI = GUICreate('',$hGUI_x_size,$hGUI_y_size,-1,-1,$WS_POPUP)
    GUISetBkColor($COLOR_GREEN)
    GUISetState(@SW_SHOWNOACTIVATE)
    ; Done


    ; Define the Squares
    Local $aHoles[5][4] = _
    [[42,140,41,126], _ ;x1=42,x2=140,y1=41,y2=126
    [277,321,19,131], _ ;x1=277,x2=321,y1=19,y2=131
    [174,353,164,243], _ ;x1=174,x2=353,y1=164,y2=243
    [32,110,204,345], _ ;x1=32,x2=110,y1=204,y2=345
    [215,323,293,392]] ;x1=215,x2=323,y1=293,y2=392


    _ArrayDisplay($aHoles,'Squares x1x2y1y2 data')

    ; Create them
    GUICreateHolesByArray($hGUI,$aHoles,$hGUI_x_size,$hGUI_y_size)

    WinSetOnTop($hGUI,'',1)


    While Sleep(100)
    WEnd

#EndRegion

#Region Low-Level: Functions
    ; $aHoles: [n][0]=x1,[n][1]=x2,[n][2]=y1,[n][3]=y2
    Func GUICreateHolesByArray($hGUI,$aHoles,$gui_x_size = Default ,$gui_y_size = Default)
        ; Get xy size of the gui if it was not entered before
        If $gui_x_size = Default Or $gui_y_size = Default Then
            Local $pos = WinGetPos($hGUI)
            If @error Then Return SetError(@ScriptLineNumber)
            $gui_x_size = $pos[2]
            $gui_y_size = $pos[3]
        EndIf


        Local $hMain_rgn = _WinAPI_CreateRectRgn(0,0,$gui_x_size,$gui_y_size), $hAdd_rgn

        For $a = 0 To UBound($aHoles)-1
            $hAdd_rgn = _WinAPI_CreateRectRgn($aHoles[$a][0], $aHoles[$a][2], $aHoles[$a][1], $aHoles[$a][3])
            _WinAPI_CombineRgn($hMain_rgn, $hMain_rgn,$hAdd_rgn , $RGN_DIFF)
            _WinAPI_DeleteObject($hAdd_rgn)
        Next

        _WinAPI_SetWindowRgn($hGUI,$hMain_rgn)
        _WinAPI_DeleteObject($hMain_rgn)
    EndFunc
#EndRegion

 

Hope this helps someone

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