Global variables should ALWAYS be declared at the beginning, even if you are going to use them later. You're right, they don't HAVE to be, but definately should be. Just declare them at the beginning and use them later. As far as the code goes, AndyG is right. The best way to find the mouse coordinates relative to the client area of the gui is to use MouseCoordMode. Here is an example of how the code should be written:
#include <GUIConstantsEx.au3>
$hGUI = GUICreate('Test', 200, 200)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
$MousePos = _MouseGetWinPos($hGUI)
ToolTip($MousePos[0] & ', ' & $MousePos[1])
WEnd
Func _MouseGetWinPos($hWnd)
$Opt = Opt("MouseCoordMode", 2)
$Pos = MouseGetPos()
Opt("MouseCoordMode", $Opt)
Return $Pos
EndFunc ;==>_MouseGetWinPos2