Sign in to follow this  
Followers 0
peter1234

example of dragging regions with transparent backgrounds

1 post in this topic

#1 ·  Posted (edited)

This may be too trivial to post, but it took me a while to figure it out, so I though it might be a helpful post. If someone knows of better way to do it, please post where I can look for info. In case it is not obvious, you can click through the transparent part of the upper region to drag the region under it.

;***********************************************************************************
;  DRAG  2 TRANSPARENT REGIONS DEMO  
;  NOTES - 1. the BMP and BMP2RGN.dll must be in same folder as script for this demo
;         2. click mouse on NON-transparent part of region to be dragged 
;         3. use ESC key to terminate script
;         4. BMP2RGN.dll by Larry, SetWindowRgn by Larry, GUICtrlCreatePic by Larry, _IsPressed by ezzetabi
;         5. special thanks to jonk for his great suggestion about checking focus
;         6. does not require beta AutoIt 
;         7. REV: 05.12.27C
;************************************************************************************
#include <GUIConstants.au3>

;*****************************
;   functions
;*****************************

Func _IsPressed($hexKey)   
    Local $aR, $bRv
    $hexKey = '0x' & $hexKey
    $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
    If $aR[0] <> 0 Then
         $bRv = 1
    Else
          $bRv = 0
    EndIf
    Return $bRv
EndFunc 

Func Terminate()
    GUIDelete ( $gui1 )
    GUIDelete ( $gui2 )
    Exit 
EndFunc

Func SetWindowRgn($h_win, $rgn)   
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $rgn, "int", 1)
EndFunc 

Func _DragRegion ($gui,$reg_x,$reg_y,ByRef $x,ByRef $y)  
    Local $pos[2],$xm,$ym,$dx,$dy
    $pos = MouseGetPos()
    $xm=$pos[0]
    $ym=$pos[1] 
    If ($xm<$x) or ($xm>($x+$reg_x)) then Return
    If ($ym<$y) or ($ym>($y+$reg_y)) then Return
    $dx=$xm-$x  
    $dy=$ym-$y
    while _IsPressed(01) = 1 ; left mouse button
        $pos = MouseGetPos()
        $xm=$pos[0]
        $ym=$pos[1]
        $x = $xm - $dx
        $y = $ym - $dy
        WinMove ( $gui, "", $x, $y )
    wend        
    Return  
EndFunc

;*****************************
;   inputs for gui1
;*****************************
$reg_bmp1 = "Santa.bmp" ; enter bmp to use for region
$reg_x1=350          ; enter bmp x size in pixels
$reg_y1=120          ; enter bmo y size in pixels
$red1 = 255          ; enter red interger value of transpartent color
$green1  = 255        ; enter green  interger value of transpartent color
$blue1 = 255            ; enter blue interger value of transpartent color
$x_start1 = 50        ; enter original x coordinate to be used for region top right corner
$y_start1 = 100      ; enter original y coordinate to be used for region top right corner

;*****************************
;   make gui1
;*****************************
$gui1 = GUICreate("gui1",$reg_x1,$reg_y1,$x_start1,$y_start1,$WS_POPUP)  
GUICtrlCreatePic($reg_bmp1,0,0,$reg_x1,$reg_y1 )   
$a = DLLCall(".\BMP2RGN.dll","int","BMP2RGN", _
    "str",$reg_bmp1, "int",$red1, "int",$green1, "int",$blue1)  
SetWindowRgn($gui1, $a[0])
GUISetState(@SW_SHOW,$gui1 )
$x1=$x_start1
$y1=$y_start1
WinMove ( $gui1, "", $x1, $y1 )
$title1=WinGetTitle("")

;*****************************
;   inputs for gui2
;*****************************
$reg_bmp2 = "Santa.bmp" ; enter bmp to use for region
$reg_x2=350          ; enter bmp x size in pixels
$reg_y2=120          ; enter bmo y size in pixels
$red2 = 255          ; enter red interger value of transpartent color
$green2  = 255        ; enter green  interger value of transpartent color
$blue2 = 255            ; enter blue interger value of transpartent color
$x_start2 = 150       ; enter original x coordinate to be used for region top right corner
$y_start2 = 200      ; enter original y coordinate to be used for region top right corner

;*****************************
;   make gui2
;*****************************
$gui2 = GUICreate("gui2",$reg_x2,$reg_y2,$x_start2,$y_start2,$WS_POPUP)  
GUICtrlCreatePic($reg_bmp2,0,0,$reg_x2,$reg_y2 )   
$a = DLLCall(".\BMP2RGN.dll","int","BMP2RGN", _
    "str",$reg_bmp2, "int",$red2, "int",$green2, "int",$blue2)  
SetWindowRgn($gui2, $a[0])
GUISetState(@SW_SHOW,$gui2 )    
$x2=$x_start2
$y2=$y_start2
WinMove ( $gui2, "", $x2, $y2 )
$title2=WinGetTitle("")

;*****************************
;   script
;*****************************
HotKeySet("{ESC}", "Terminate")

while 1
    If  $title1=WinGetTitle("") then  _DragRegion ($gui1,$reg_x1,$reg_y1,$x1,$y1)  
    If  $title2=WinGetTitle("") then  _DragRegion ($gui2,$reg_x2,$reg_y2,$x2,$y2)   
    sleep (100)
wend

Santa.bmp

BMP2RGN.dll

Edited by peter1234

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