Sign in to follow this  
Followers 0
monoscout999

Help me formating and fixing an UDF

3 posts in this topic

#1 ·  Posted (edited)

Helo forum. i was thinking on this thread when i do this and i guess that i was in the mood to do this UDF that replaces the png images that the user of that thread use.

This UDF do an efect of many GUIs with transparency whit a hole in the middle. i want to you give me some advice about it, some improvements ideas, anything that may help me to finish the UDF and make it useful and efficent and more fast.

i left an example and the UDF.. and start to beat me.

Example

#include "InvertRoundRegionUDF.au3"
HotKeySet("{esc}","_exit")
HotKeySet("{UP}","_up")
HotKeySet("{DOWN}","_down")
global $inradio = 80
Const $outradio = 600
$hGUI = _CreateInvRndRgnGUIs($inradio, $outradio, 10, 0x00ffff, 10, 30)
While True
    sleep(1000)
WEnd
Func _exit()
    _DeleleteInvRndRgnsGUIs("",$hGUI)
    exit
EndFunc
Func _up()
    $inradio += 5
    $hRgn = _CreateInvRndRgns($inradio, $outradio, 10)
    _UpdateInvRndRgnGUI($hGUI, $hRgn)
EndFunc
Func _down()
    $inradio -= 5
    $hRgn = _CreateInvRndRgns($inradio, $outradio, 10)
    _UpdateInvRndRgnGUI($hGUI, $hRgn)
EndFunc

InvertRoundRegionUDF.au3

#include-once
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <StaticConstants.au3>

; #INDEX# =======================================================================================================================
; Title .........: InvertRoundRegion
; AutoIt Version : 3.3.6.1
; Description ...: Functions for the efect creation of Round Empty Areas.
; Author(s) .....: monoscout999
; ===============================================================================================================================

; #CURRENT# =====================================================================================================================
;_CreateInvRndRgn
;_CreateInvRndRgns
;_CreateInvRndRgnGUI
;_CreateInvRndRgnGUIs
;_UpdateInvRndRgnGUI
;_DeleleteInvRndRgnsGUIs
; ===============================================================================================================================

; #FUNCTION# ====================================================================================================================
; Name...........: _CreateInvRndRgn
; Description ...: Create a Inverted Round Region.
; Syntax.........: _CreateInvRndRgn($iradio)
; Parameters ....: $iradio  - Radio of the Round Clear Area
; Return values .: Success      - Returns a Region handle
;                  Failure      - False
; Author ........: Agustìn Rojas (monoscout999)
; Remarks .......:
; ===============================================================================================================================
Func _CreateInvRndRgn($iradio)
    Local $iHalf = $iradio / 2
    Local $iXCenter = @DesktopWidth / 2
    Local $iYCenter = @DesktopHeight / 2
    $hRgn1 = _WinAPI_CreateRectRgn(0, 0, @DesktopWidth, @DesktopHeight)
    $hRgn2 = _WinAPI_CreateRoundRectRgn($iXCenter - $iHalf, $iYCenter - $iHalf, $iXCenter + $iHalf, $iYCenter + $iHalf, $iradio * 2, $iradio * 2)
    _WinAPI_CombineRgn($hRgn1, $hRgn1, $hRgn2, $RGN_DIFF)
    Return $hRgn1
EndFunc   ;==>_CreateInvRndRgn

; #FUNCTION# ====================================================================================================================
; Name...........: _CreateInvRndRgns
; Description ...: Create a group of Inverted Round Region.
; Syntax.........: _CreateInvRndRgns($iInternalRadio, $iOutsideRadio, $iQuantity)
; Parameters ....: $iInternalRadio  - Internal radio of the Round Clear Area.
;                  $iOutsideRadio   - Outsider radio of the Round Clear Area.
;                  $iQuantity       - Amount of Regions to get between the inner radio and the outer radio.
; Return values .: Success      - Returns an array containing Regions handles.
;                  Failure      - False
; Author ........: Agustìn Rojas (monoscout999)
; Remarks .......:
; ===============================================================================================================================
Func _CreateInvRndRgns($iInternalRadio, $iOutsideRadio, $iQuantity)
    If $iOutsideRadio < $iInternalRadio Then Return SetError(1, "", False)
    If $iOutsideRadio - $iInternalRadio < $iQuantity Then Return SetError(2, "", False)
    Local $step = ($iOutsideRadio - $iInternalRadio) / $iQuantity
    Local $Rgns[$iQuantity]
    Local $radio = $iInternalRadio
    For $i = 0 To $iQuantity - 1
        $Rgns[$i] = _CreateInvRndRgn($radio)
        $radio += $step
    Next
    Return $Rgns
EndFunc   ;==>_CreateInvRndRgns

; #FUNCTION# ====================================================================================================================
; Name...........: _CreateInvRndRgnGUI
; Description ...: Create a semi transparent Gui of the size of the screen with a color and a hole in the middle.
; Syntax.........: _CreateInvRndRgnGUI($iradio, $hColor, $itrans)
; Parameters ....: $iradio    - Radio of the Round Clear Area.
;                  $hColor    - Color of the GUI.
;                  $itrans    - Transparency level.
; Return values .: Success      - Returns an handle for the GUI.
;                  Failure      - False
; Author ........: Agustìn Rojas (monoscout999)
; Remarks .......:
; ===============================================================================================================================
Func _CreateInvRndRgnGUI($iradio, $hColor, $itrans)
    If $itrans < 0 Or $itrans > 255 Then Return SetError(1, "", False)
    Local $BkGUI = GUICreate("InvrndRgnGUI", @DesktopWidth, @DesktopHeight, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetBkColor($hColor)
    WinSetTrans($BkGUI, "", $itrans)
    Local $hRgn = _CreateInvRndRgn($iradio)
    _WinAPI_SetWindowRgn($BkGUI, $hRgn)
    GUISetState(@SW_SHOW, $BkGUI)
    Return $BkGUI
EndFunc   ;==>_CreateInvRndRgnGUI

; #FUNCTION# ====================================================================================================================
; Name...........: _CreateInvRndRgnGUIs
; Description ...: Create many semi transparent Guis with holes in the center to make an efect.
; Syntax.........: _CreateInvRndRgnGUIs($iInternalRadio, $iOutsideRadio, $iQuantity, $hColor, $iMinTrans, $iMaxTrans)
; Parameters ....: $iInternalRadio   - Inner radio of the Round Clear Area.
;                  $iOutsideRadio    - Outer radio of the Round Clear Area.
;                  $iQuantity    - Amount of GUIs to make.
;                  $hColor       - Color of the GUIs.
;                  $iMinTrans    - Minimun transparency level.
;                  $iMaxTrans    - Maximun Transparency level.
; Return values .: Success      - Returns an aray containing the GUIs Handles..
;                  Failure      - False
; Author ........: Agustìn Rojas (monoscout999)
; Remarks .......: Not go so far with the $iQuantity you can idle the PC. 10 is an aceptable number.
; ===============================================================================================================================
Func _CreateInvRndRgnGUIs($iInternalRadio, $iOutsideRadio, $iQuantity, $hColor, $iMinTrans, $iMaxTrans)
    If $iOutsideRadio < $iInternalRadio Then Return SetError(1, "", False)
    If $iOutsideRadio - $iInternalRadio < $iQuantity Then Return SetError(2, "", False)
    If $iMinTrans < 0 Or $iMinTrans > 255 Then Return SetError(3, 1, False)
    If $iMaxTrans < 0 Or $iMaxTrans > 255 Then Return SetError(3, 2, False)
    If $iMaxTrans < $iMinTrans Then Return SetError(3, 3, False)
    Local $step1 = ($iMaxTrans - $iMinTrans) / $iQuantity
    Local $step2 = ($iOutsideRadio - $iInternalRadio) / $iQuantity
    Local $itrans = $iMinTrans
    Local $iradio = $iInternalRadio
    Local $hGUIs[$iQuantity]
    For $i = 0 To $iQuantity - 1
        $hGUIs[$i] = _CreateInvRndRgnGUI($iradio, $hColor, $itrans)
        $itrans += $step1
        $iradio += $step2
    Next
    Return $hGUIs
EndFunc   ;==>_CreateInvRndRgnGUIs

; #FUNCTION# ====================================================================================================================
; Name...........: _UpdateInvRndRgnGUI
; Description ...: Update the Round Region/s of a GUI or a group of them. Also can update the color
; Syntax.........:  _UpdateInvRndRgnGUI($hGUI, $hRgn[, $hColor = false])
; Parameters ....: $hGUI    - Handle of a GUI or an array of GIUs.
;                  $hRgn    - Handle of a region or an array of regions.
;                  $hColor  - Color for updating GUI or GUIs.
; Return values .: Success      - True
;                  Failure      - False
; Author ........: Agustìn Rojas (monoscout999)
; Remarks .......:
; ===============================================================================================================================
Func _UpdateInvRndRgnGUI($hGUI, $hRgn, $hColor = false)
    If IsArray($hGUI) And IsArray($hRgn) Then
        If Ubound($hGUI) <> Ubound($hRgn) Then Return SetError(2, "", False)
        For $i = 0 To Ubound($hGUI) - 1
            _WinAPI_SetWindowRgn($hGUI[$i], $hRgn[$i])
            If $hColor then Guisetbkcolor($hColor,$hGUI[$i])
        Next
        Return True
    ElseIf $hGUI And $hRgn Then
        _WinAPI_SetWindowRgn($hGUI, $hRgn)
        If $hColor then Guisetbkcolor($hColor,$hGUI)
        Return True
    Else
        Return SetError(1, "", False)
    EndIf
EndFunc   ;==>_UpdateInvRndRgnGUI

; #FUNCTION# ====================================================================================================================
; Name...........: _DeleleteInvRndRgnsGUIs($hRgn = False, $InvRndRgnGUI = False)
; Description ...: Delete the Round Regions handles or GUIs
; Syntax.........:  _DeleleteInvRndRgnsGUIs([$hRgn = False][, $InvRndRgnGUI = False])
; Parameters ....: $hRgn            - Handle of a region or an array of regions.
;                  $InvRndRgnGUI    - Handle of a GUI or an array of GIUs.
; Return values .: Success      - True
;                  Failure      - False
; Author ........: Agustìn Rojas (monoscout999)
; Remarks .......: Use this after the use of Invert Round Regions UDF for cleaning resources.
;                  If you only need to clear the GUI/s leave an space in the $hRgn parameter
;                  Ex: _DeleleteInvRndRgnsGUIs("", $InvRndRgnGUI)
; ===============================================================================================================================
Func _DeleleteInvRndRgnsGUIs($hRgn = False, $InvRndRgnGUI = False)
    If IsArray($hRgn) Then
        For $i = 0 To UBound($hRgn) - 1
            _WinAPI_DeleteObject($hRgn[$i])
        Next
        Return True
    ElseIf $hRgn Then
        _WinAPI_DeleteObject($hRgn)
        Return True
    EndIf
    If IsArray($InvRndRgnGUI) Then
        For $i = 0 To UBound($InvRndRgnGUI) - 1
            GUIDelete($InvRndRgnGUI[$i])
        Next
        Return True
    ElseIf $InvRndRgnGUI Then
        GUIDelete($InvRndRgnGUI)
        Return True
    EndIf
    Return False
EndFunc   ;==>_DeleleteInvRndRgnsGUIs

Also thanks to melba23 for the _GUICreateInvRect idea :)

Edited by monoscout999

Share this post


Link to post
Share on other sites



Looks like you mean "Radius" when you write "Radio". If true ...

Other than that. Code-format Look fine. Although your code-problem might need some more elaboration.


"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

Looks like you mean "Radius" when you write "Radio". If true ...

Other than that. Code-format Look fine. Although your code-problem might need some more elaboration.

My mistake Radio from spanish is Radios :) i will edit that, also i want to change to using GDI+ instead of the GUI creation method.

Thanks.

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