Jump to content
rizaado

Function GUICtrlGetPos

Recommended Posts

rizaado
Func GUICtrlGetPos($iControlID)
    Local $hControlID = GUICtrlGetHandle($iControlID)
    Local $aControlPos[2]
    $aControlPos[0] = ControlGetPos($hControlID, "", 0)[0]
    $aControlPos[1] = ControlGetPos($hControlID, "", 0)[1]
    Return $aControlPos
EndFunc   ;==>GUICtrlGetPos
Local $hGUI = GUICreate("GUICtrlGetPos", _
        0, _
        0, _
        1, _
        1, _
        $WS_SYSMENU + $WS_MAXIMIZE + $WS_MAXIMIZEBOX + $DS_MODALFRAME)
Local $idPic = GUICtrlCreatePic("tree.gif", 20, 40, 11, 26)
GUISetState(@SW_SHOW)
MsgBox($MB_SYSTEMMODAL, "Left", GUICtrlGetPos($idPic)[0])
MsgBox($MB_SYSTEMMODAL, "Top", GUICtrlGetPos($idPic)[1])
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
GUIDelete($hGUI)

Purpose: Get the left(x) and top(y) of control.

Edited by rizaado

Share this post


Link to post
Share on other sites
argumentum
Func GUICtrlGetPos($iControlID)
    Local $a = ControlGetPos(GUICtrlGetHandle($iControlID),"",0)
    If @error Then
        Local $a[4]=[-1,-1,-1,-1]
        Return SetError(1,0,$a)
    EndIf
    Return SetError(0,0,$a)
EndFunc

 

Edited by argumentum
corrected the function

Share this post


Link to post
Share on other sites
rizaado

Your variant of a function GUICtrlGetPos is wrong.

ControlGetPos:

Return Value

Success:an array containing the size and the control's position relative to its client window:
    $aArray[0] = X position
    $aArray[1] = Y position
    $aArray[2] = Width
    $aArray[3] = Height
Failure:sets the @error flag to 1.
Edited by rizaado

Share this post


Link to post
Share on other sites
rizaado

Divide GUICtrlGetPos into two functions - "getLeft" and "getTop"! It is better solution.

Edited by rizaado

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

×