Sign in to follow this  
Followers 0
jcpetu

Window issue 2

1 post in this topic

Hi again, I'm trying to create two popup windows resizable and movable. the point is that I can only resize one of them. I'm getting in trouble to detect what window is the mouse over.

Any help will be appreciated.

thanks in advance and regards.

#include <WinAPI.au3>
#include <GuiConstantsEx.au3>
#include <Windowsconstants.au3>
#include <SendMessage.au3>

Global Const $SC_DRAGMOVE = 0xF012

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

Global Const $iMargin = 4; Set distance from edge of window where resizing is possible
Global Const $iGUI1MinX = 50, $iGUI1MinY = 50, $iGUI1MaxX = 300, $iGUI1MaxY = 300; Set max and min GUI1 sizes
Global Const $iGUI2MinX = 50, $iGUI2MinY = 50, $iGUI2MaxX = 300, $iGUI2MaxY = 300; Set max and min GUI2 sizes

Global $hGUI, $hGUI2, $hGUI3, $hGUI4, $hGUI5, $hGUI6

$hGUI = GUICreate("", 100, 100, 200, 200, $WS_POPUP, $WS_EX_TRANSPARENT, _WinAPI_GetDesktopWindow())
GUISetBkColor(0x00FF00)
GUISetState()

$hGUI2 = GUICreate("", 100, 100, 100, 100, BitOR($WS_POPUP, $WS_EX_MDICHILD), _WinAPI_GetDesktopWindow(), $hGUI)
GUISetBkColor(0xAFFF00)
GUISetState()

; Register message handlers
GUIRegisterMsg($WM_MOUSEMOVE, "_SetCursor") ; For cursor type change
GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") ; For resize/drag
GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO") ; For GUI size limits

While 1
    Sleep(10)
WEnd

; Set cursor to correct resizing form if mouse is over a border
Func _SetCursor()
    Local $iCursorID
    Switch _Check_Border()
        Case 0
            $iCursorID = 2
        Case 1, 2
            $iCursorID = 13
        Case 3, 6
            $iCursorID = 11
        Case 5, 7
            $iCursorID = 10
        Case 4, 8
            $iCursorID = 12
    EndSwitch
    GUISetCursor($iCursorID, 1)
EndFunc   ;==>_SetCursor

; Check cursor type and resize/drag window as required
Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    Local $iCursorType = _Check_Border()
    If $iCursorType > 0 Then ; Cursor is set to resizing style so send appropriate resize message
        $iResizeType = 0xF000 + $iCursorType
        _SendMessage(WinGetHandle("[ACTIVE]"), $WM_SYSCOMMAND, $iResizeType, 0)
    Else
        Local $aCurInfo = GUIGetCursorInfo(WinGetHandle("[ACTIVE]"))
        If Not @error And $aCurInfo[4] = 0 Then _SendMessage(WinGetHandle("[ACTIVE]"), $WM_SYSCOMMAND, $SC_DRAGMOVE, 0); Mouse not over a control
    EndIf
EndFunc   ;==>_WM_LBUTTONDOWN

; Determines if mouse cursor over a border
Func _Check_Border()
    ;_WinAPI_GetWindow(WinGetHandle("[ACTIVE]"),$GW_HWNDNEXT)
    Local $aCurInfo = GUIGetCursorInfo(WinGetHandle("[ACTIVE]"))
    If @error Or Not IsArray($aCurInfo) Then Return SetError(1)
    Local $aWinPos = WinGetPos(WinGetHandle("[ACTIVE]"))
    Local $iSide, $iTopBot
    If $aCurInfo[0] < $iMargin Then $iSide = 1
    If $aCurInfo[0] > $aWinPos[2] - $iMargin Then $iSide = 2
    If $aCurInfo[1] < $iMargin Then $iTopBot = 3
    If $aCurInfo[1] > $aWinPos[3] - $iMargin Then $iTopBot = 6
    Return $iSide + $iTopBot
EndFunc   ;==>_Check_Border

; Set min and max GUI sizes
Func _WM_GETMINMAXINFO($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $WPARAM
    $tMinMaxInfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    Switch $hWnd
        Case $hGUI
            DllStructSetData($tMinMaxInfo, 7, $iGUI1MinX)
            DllStructSetData($tMinMaxInfo, 8, $iGUI1MinY)
            DllStructSetData($tMinMaxInfo, 9, $iGUI1MaxX)
            DllStructSetData($tMinMaxInfo, 10, $iGUI1MaxY)
        Case $hGUI2
            DllStructSetData($tMinMaxInfo, 7, $iGUI2MinX)
            DllStructSetData($tMinMaxInfo, 8, $iGUI2MinY)
            DllStructSetData($tMinMaxInfo, 9, $iGUI2MaxX)
            DllStructSetData($tMinMaxInfo, 10, $iGUI2MaxY)
    EndSwitch
    Return 0
EndFunc   ;==>_WM_GETMINMAXINFO

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

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