Jump to content

WinAPI Hole move GUI


Terenz
 Share

Recommended Posts

Hi :D

The script:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

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

Local $hWnd = GUICreate("", 100, 100, -1, -1, $WS_POPUP)
Local $hLabel = GUICtrlCreateLabel("", 0, 0, 100, 100)
Local $aPos = WinGetPos($hWnd)
_Hole($hWnd, 15, 15, $aPos[2] - 2 * 15, $aPos[3] - 2 * 15, $aPos[2], $aPos[3])
GUISetBkColor(0x000000)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_PRIMARYDOWN
            Drag_Window()
    EndSwitch
WEnd


Func _Hole($h_win, $i_x, $i_y, $i_sizew, $i_sizeh, $width, $Height)
    Local $outer_rgn, $inner_rgn, $combined_rgn
    $outer_rgn = _WinAPI_CreateRectRgn(0, 0, $width, $Height)
    $inner_rgn = _WinAPI_CreateRectRgn($i_x, $i_y, $i_x + $i_sizew, $i_y + $i_sizeh)
    $combined_rgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    _WinAPI_CombineRgn($combined_rgn, $outer_rgn, $inner_rgn, $RGN_DIFF)
    _WinAPI_DeleteObject($outer_rgn)
    _WinAPI_DeleteObject($inner_rgn)
    _WinAPI_SetWindowRgn($h_win, $combined_rgn)
EndFunc   ;==>_Hole

Func Drag_Window()
    _SendMessage($hWnd, $WM_SYSCOMMAND, 0xF012, 0)
EndFunc

Func _Exit()
    Exit
EndFunc   ;==>_Exit

I don't know how is the author of Hole() sorry for that ( EDIT: Probably GaryFrost )

Pratically i want to use the mouse for moving the window. I know there is a tutorial for doing that:

Moving and Resizing PopUp GUIs

But the problem is the mouse isn't recognized "inside" the hole but only in the black border. How to move the entire GUI? I don't want the click through feature. Many Thanks

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

I have think to use a child gui ( semi-trasparent ) for move the black square but i have a problem :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>

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

Local $hWnd1, $hWnd2

$hWnd2 = GUICreate("", 100, 100, -1, -1, $WS_POPUP)
Local $aPos = WinGetPos($hWnd2)
_Hole($hWnd2, 15, 15, $aPos[2] - 2 * 15, $aPos[3] - 2 * 15, $aPos[2], $aPos[3])
GUISetBkColor(0x000000)
GUISetState()

$hWnd1 = GUICreate("", 70, 70, -1, -1, $WS_POPUP, $WS_EX_MDICHILD, $hWnd2)
GUISetBkColor(0xFF0000)
GUISetState()

While 1
    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $hWnd1
            Switch $aMsg[0]
                Case $GUI_EVENT_PRIMARYDOWN
                    _SendMessage($hWnd2, $WM_SYSCOMMAND, 0xF012, 0)
            EndSwitch
        Case $hWnd2
            Switch $aMsg[0]
                Case $GUI_EVENT_PRIMARYDOWN
                    _SendMessage($hWnd2, $WM_SYSCOMMAND, 0xF012, 0)
            EndSwitch
    EndSwitch
WEnd

Func _Hole($h_win, $i_x, $i_y, $i_sizew, $i_sizeh, $width, $Height)
    Local $outer_rgn, $inner_rgn, $combined_rgn
    $outer_rgn = _WinAPI_CreateRectRgn(0, 0, $width, $Height)
    $inner_rgn = _WinAPI_CreateRectRgn($i_x, $i_y, $i_x + $i_sizew, $i_y + $i_sizeh)
    $combined_rgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    _WinAPI_CombineRgn($combined_rgn, $outer_rgn, $inner_rgn, $RGN_DIFF)
    _WinAPI_DeleteObject($outer_rgn)
    _WinAPI_DeleteObject($inner_rgn)
    _WinAPI_SetWindowRgn($h_win, $combined_rgn)
EndFunc   ;==>_Hole

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Is not centered but i don't care now

If i move using the black square, i don't have problem

If i move using the red square, well work one time yes, and one time no :

Click = move = Ok

Click = nothing happens

Click = move = Ok

Click = nothing happens

And so on, where is the mistake?

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

Not very clean, but a simple way :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>


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

Local $hWnd1, $hWnd2

$hWnd2 = GUICreate("", 100, 100, -1, -1, $WS_POPUP)
Local $aPos = WinGetPos($hWnd2)
_Hole($hWnd2, 15, 15, $aPos[2] - 2 * 15, $aPos[3] - 2 * 15, $aPos[2], $aPos[3])
GUISetBkColor(0x000000)
GUISetState()

$hWnd1 = GUICreate("", 100, 100, 0, 0, $WS_POPUPWINDOW, $WS_EX_MDICHILD, $hWnd2)
GUICtrlCreateLabel("", 0, 0, 100, 100, -1, $GUI_WS_EX_PARENTDRAG)
WinSetTrans($hWnd1, "", 2)
GUISetState()

GUIRegisterMsg($WM_MOVE, "_WM_MOVE")

While 1
    Sleep(100)

WEnd

Func _Hole($h_win, $i_x, $i_y, $i_sizew, $i_sizeh, $width, $Height)
    Local $outer_rgn, $inner_rgn, $combined_rgn
    $outer_rgn = _WinAPI_CreateRectRgn(0, 0, $width, $Height)
    $inner_rgn = _WinAPI_CreateRectRgn($i_x, $i_y, $i_x + $i_sizew, $i_y + $i_sizeh)
    $combined_rgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    _WinAPI_CombineRgn($combined_rgn, $outer_rgn, $inner_rgn, $RGN_DIFF)
    _WinAPI_DeleteObject($outer_rgn)
    _WinAPI_DeleteObject($inner_rgn)
    _WinAPI_SetWindowRgn($h_win, $combined_rgn)
EndFunc   ;==>_Hole

Func _Exit()
    Exit
EndFunc   ;==>_Exit



Func _WM_MOVE($hWndGUI, $MsgID, $WParam, $LParam)
    Local $iPosX = BitAND($LParam, 0xFFFF)
    Local $iPosY = BitShift($LParam, 16)

    WinMove($hWnd2, "", $iPosX, $iPosY)
EndFunc

But, what is the goal ?

Link to comment
Share on other sites

i think the goal is understand why it locks up when you drag it around by the small box.  I added a line to make the small box change colors when you dragged it, directly after the color changes you wont be able to move that gui by that box again until you left click on it once.   Even if you drag it around by the parent you cant go back to dragging it by the small box until you left click in that area...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>

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

Local $hWnd1, $hWnd2

$hWnd2 = GUICreate("", 100, 100, -1, -1, $WS_POPUP)
Local $aPos = WinGetPos($hWnd2)
_Hole($hWnd2, 15, 15, $aPos[2] - 2 * 15, $aPos[3] - 2 * 15, $aPos[2], $aPos[3])
GUISetBkColor(0x000000)
GUISetState()

$hWnd1 = GUICreate("", 70, 70, -1, -1, $WS_POPUP, $WS_EX_MDICHILD, $hWnd2)
GUISetBkColor(0xFF0000)
GUISetState()

While 1
    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $hWnd1
            Switch $aMsg[0]
                Case $GUI_EVENT_PRIMARYDOWN
                    _SendMessage($hWnd2, $WM_SYSCOMMAND, 0xF014, 0)
                GUISetBkColor(random(0x000000 , 0xFFFFFF))
            EndSwitch
        Case $hWnd2
            Switch $aMsg[0]
                Case $GUI_EVENT_PRIMARYDOWN
                    _SendMessage($hWnd2, $WM_SYSCOMMAND, 0xF014, 0)

            EndSwitch
    EndSwitch
WEnd

Func _Hole($h_win, $i_x, $i_y, $i_sizew, $i_sizeh, $width, $Height)
    Local $outer_rgn, $inner_rgn, $combined_rgn
    $outer_rgn = _WinAPI_CreateRectRgn(0, 0, $width, $Height)
    $inner_rgn = _WinAPI_CreateRectRgn($i_x, $i_y, $i_x + $i_sizew, $i_y + $i_sizeh)
    $combined_rgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    _WinAPI_CombineRgn($combined_rgn, $outer_rgn, $inner_rgn, $RGN_DIFF)
    _WinAPI_DeleteObject($outer_rgn)
    _WinAPI_DeleteObject($inner_rgn)
    _WinAPI_SetWindowRgn($h_win, $combined_rgn)
EndFunc   ;==>_Hole

Func _Exit()
    Exit
EndFunc   ;==>_Exit

JGunich, Your solution has tracers on my system when i drag the boxes around, if the goal is space themed that solution is sexy.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>


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

Local $hWnd1, $hWnd2

$hWnd2 = GUICreate("", 100, 100, -1, -1, $WS_POPUP)
Local $aPos = WinGetPos($hWnd2)
_Hole($hWnd2, 15, 15, $aPos[2] - 2 * 15, $aPos[3] - 2 * 15, $aPos[2], $aPos[3])
GUISetBkColor(0x000000)
GUISetState()

$hWnd1 = GUICreate("", 60, 60, 0, 0, $WS_POPUPWINDOW, $WS_EX_MDICHILD, $hWnd2)
GUICtrlCreateLabel("", 0, 0, 100, 100, -1, $GUI_WS_EX_PARENTDRAG)
GUISetBkColor(0xFF0000)
;~ WinSetTrans($hWnd1, "", 2)

GUISetState()

GUIRegisterMsg($WM_MOVE, "_WM_MOVE")

While 1
    Sleep(100)

WEnd

Func _Hole($h_win, $i_x, $i_y, $i_sizew, $i_sizeh, $width, $Height)
    Local $outer_rgn, $inner_rgn, $combined_rgn
    $outer_rgn = _WinAPI_CreateRectRgn(0, 0, $width, $Height)
    $inner_rgn = _WinAPI_CreateRectRgn($i_x, $i_y, $i_x + $i_sizew, $i_y + $i_sizeh)
    $combined_rgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    _WinAPI_CombineRgn($combined_rgn, $outer_rgn, $inner_rgn, $RGN_DIFF)
    _WinAPI_DeleteObject($outer_rgn)
    _WinAPI_DeleteObject($inner_rgn)
    _WinAPI_SetWindowRgn($h_win, $combined_rgn)
EndFunc   ;==>_Hole

Func _Exit()
    Exit
EndFunc   ;==>_Exit



Func _WM_MOVE($hWndGUI, $MsgID, $WParam, $LParam)
    Local $iPosX = BitAND($LParam, 0xFFFF)
    Local $iPosY = BitShift($LParam, 16)

    WinMove($hWnd2, "", $iPosX, $iPosY)
EndFunc
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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