John117 Posted December 7, 2007 Share Posted December 7, 2007 (edited) Im trying to see if the mouse is over my GUI - Can this be done in an easer way?. Please Help $ParentWin_Width = 450 $ParentWin_Height = 700 $ParentWin_Left = ((@DesktopWidth - $ParentWin_Width) / 2) $Top = 25 Global $ParentWin = GUICreate("Example", 450, $ParentWin_Height, $ParentWin_Left, $Top) GUISetState(@SW_SHOW, $ParentWin) While 1 Sleep(2000) $pos = MouseGetPos() If $pos[0] > $ParentWin_Left Then If $pos[0] < $ParentWin_Left + $ParentWin_Width Then If $pos[1] > $Top Then If $pos[1] < $Top + $ParentWin_Height Then MsgBox(0, "Mouse x,y:", $pos[0] & "," & $pos[1]) EndIf EndIf EndIf EndIf WEnd Edited December 7, 2007 by Hatcheda Link to comment Share on other sites More sharing options...
Valuater Posted December 7, 2007 Share Posted December 7, 2007 Maybe.... #include <GUIConstants.au3> $ParentWin_Width = 450 $ParentWin_Height = 700 $ParentWin_Left = ((@DesktopWidth - $ParentWin_Width) / 2) $Top = 25 Global $ParentWin = GUICreate("HaloWars", 450, $ParentWin_Height, $ParentWin_Left, $Top) $back = GUICtrlCreateLabel("", 0,0,$ParentWin_Width, $ParentWin_Height) GUICtrlSetState( -1, $gui_disable) GUISetState(@SW_SHOW, $ParentWin) While 1 If GUIGetMsg() = -3 then Exit $info = GUIGetCursorInfo($ParentWin) If $info[4] = $back Then ToolTip("You are over the GUI" ) Else ToolTip("") EndIf WEnd 8) Link to comment Share on other sites More sharing options...
John117 Posted December 7, 2007 Author Share Posted December 7, 2007 Hey bud, thanks for the reply Link to comment Share on other sites More sharing options...
Valuater Posted December 7, 2007 Share Posted December 7, 2007 Welcome a little better... requires the GUI be active #include <GUIConstants.au3> $ParentWin_Width = 450 $ParentWin_Height = 700 $ParentWin_Left = ((@DesktopWidth - $ParentWin_Width) / 2) $Top = 25 Global $ParentWin = GUICreate("HaloWars", 450, $ParentWin_Height, $ParentWin_Left, $Top) $back = GUICtrlCreateLabel("", 0,0,$ParentWin_Width, $ParentWin_Height) GUICtrlSetState( -1, $gui_disable) GUISetState(@SW_SHOW, $ParentWin) While 1 If GUIGetMsg() = -3 then Exit $info = GUIGetCursorInfo($ParentWin) If $info[4] = $back And WinActive($ParentWin) Then ToolTip("You are over the GUI" ) Else ToolTip("") EndIf WEnd 8) Link to comment Share on other sites More sharing options...
John117 Posted December 8, 2007 Author Share Posted December 8, 2007 THanks - I'll work that in. Take a look at this expandcollapse popupGlobal $ParentWin_Width = 450 Global $ParentWin_Height = 700 Global $ParentWin_Left = ((@DesktopWidth - $ParentWin_Width) / 2) Global $Top = 25 Global $ParentWin = GUICreate("Example", 450, $ParentWin_Height, $ParentWin_Left, $Top) Opt("GUIOnEventMode", 1) HotKeySet("{ESC}", "_Custom_Exit") GUISetState(@SW_SHOW, $ParentWin) While 1 Sleep(1000) Global $size = WinGetPos($ParentWin) Global $pos = MouseGetPos() ;MouseLeft < GuiLeft If $pos[0] > $size[0] Then ;MouseRight > GuiRight If $pos[0] < ($size[0] + $size[2]) Then ;MouseTop < GuiTop If $pos[1] > $size[1] Then ;MouseBottom > GuiBottom If $pos[1] < ($size[1] + 500) Then _Expand() Else ;MsgBox(0, "if 4", "NotWorking") _Colapse() EndIf Else ;MsgBox(0, "if 3", "NotWorking") _Colapse() EndIf Else ;MsgBox(0, "if 2", "NotWorking") _Colapse() EndIf Else ;MsgBox(0, "if 1", "NotWorking") _Colapse() EndIf WEnd Func _Colapse() ;WinMove ( "title", "text", x, y [, width [, height[, speed]]] ) If $size[3] > 40 Then For $i = $ParentWin_Height To 40 Step - 5 WinMove($ParentWin, "", $size[0], $size[1], $size[2], $i) Next EndIF EndFunc ;==>_Colapse Func _Expand() ;MsgBox(0, "if 5", "working") If $size[3] = 40 Then For $i = 40 To $ParentWin_Height Step 5 WinMove($ParentWin, "", $size[0], $size[1], $size[2], $i) Next EndIf EndFunc ;==>_Expand Func _Custom_Exit() Exit EndFunc ;==> _exit() Link to comment Share on other sites More sharing options...
MrCreatoR Posted December 8, 2007 Share Posted December 8, 2007 a little betterAnd a little more better (i think)... #include <GUIConstants.au3> $ParentWin_Width = 450 $ParentWin_Height = 700 $ParentWin_Left = ((@DesktopWidth - $ParentWin_Width) / 2) $Top = 25 Global $ParentWin = GUICreate("HaloWars", 450, $ParentWin_Height, $ParentWin_Left, $Top) GUISetState(@SW_SHOW, $ParentWin) While 1 If GUIGetMsg() = -3 Then Exit If GetHoveredHwnd() = $ParentWin Then ToolTip("You are over the GUI") Else ToolTip("") EndIf WEnd Func GetHoveredHwnd() Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1)) If $iRet[0] Then Return HWnd($iRet[0]) Return SetError(1, 0, 0) EndFunc Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Valuater Posted December 8, 2007 Share Posted December 8, 2007 Pretty good there Creator! maybe the checking for the return should be IsArray() rather than $ret[0] Like this Func GetHoveredHwnd() Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1)) If IsArray($iRet) Then Return HWnd($iRet[0]) Return SetError(1, 0, 0) EndFunc 8) Link to comment Share on other sites More sharing options...
guiltyking Posted April 26, 2016 Share Posted April 26, 2016 Quote On 12/7/2007 at 6:31 AM, MrCreatoR said: #include <GUIConstants.au3> $ParentWin_Width = 450 $ParentWin_Height = 700 $ParentWin_Left = ((@DesktopWidth - $ParentWin_Width) / 2) $Top = 25 Global $ParentWin = GUICreate("HaloWars", 450, $ParentWin_Height, $ParentWin_Left, $Top) GUISetState(@SW_SHOW, $ParentWin) While 1 If GUIGetMsg() = -3 Then Exit If GetHoveredHwnd() = $ParentWin Then ToolTip("You are over the GUI") Else ToolTip("") EndIf WEnd Func GetHoveredHwnd() Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1)) If $iRet[0] Then Return HWnd($iRet[0]) Return SetError(1, 0, 0) EndFunc how to do this at on_event mode? Link to comment Share on other sites More sharing options...
InunoTaishou Posted April 26, 2016 Share Posted April 26, 2016 (edited) Dunno why you bumped a 9 year old thread instead of making a new topic but, If you're every trying to do something with a GUI there's 99.9% chance there is a window message that can do what you're trying to accomplish #include <GUIConstants.au3> #include <GUIConstants.au3> #include <WinAPISys.au3> $ParentWin_Width = 450 $ParentWin_Height = 700 $ParentWin_Left = ((@DesktopWidth - $ParentWin_Width) / 2) $Top = 25 Global $ParentWin = GUICreate("HaloWars", 450, $ParentWin_Height, $ParentWin_Left, $Top) GUISetState(@SW_SHOW, $ParentWin) GUIRegisterMsg($WM_MOUSEMOVE, WM_MOUSEMOVE) GUIRegisterMsg($WM_MOUSELEAVE, WM_MOUSELEAVE) While 1 If GUIGetMsg() = -3 Then Exit WEnd Func WM_MOUSEMOVE($hWnd, $iMsg, $wParam, $lParam) ToolTip("In window " & WinGetTitle($hWnd)) _WinAPI_TrackMouseEvent($hWnd, $TME_LEAVE) Return $GUI_RUNDEFMSG EndFunc ;==>WM_MOUSEMOVE Func WM_MOUSELEAVE($hWnd, $iMsg, $wParam, $lParam) ToolTip("Left window " & WinGetTitle($hWnd)) Return $GUI_RUNDEFMSG EndFunc ;==>WM_MOUSELEAVE Edited April 26, 2016 by InunoTaishou Link to comment Share on other sites More sharing options...
guiltyking Posted April 26, 2016 Share Posted April 26, 2016 (edited) Tks, But all posts related to mouse move i have search including your recent post does not give desired solution. Because WM message thinks it is out window when cursor is on a GUI element. Edited April 26, 2016 by guiltyking Link to comment Share on other sites More sharing options...
AutoBert Posted April 26, 2016 Share Posted April 26, 2016 This func does the job: Func _MouseIsOverHWnd($hWnd) Local $bMouseOver If not WinActive($hWnd) then return False Local $aMousePos = MouseGetPos() Local $aWinPos = WinGetPos($hWnd) if ($aMousePos[0] < $aWinPos[0] Or $aMousePos[0] > $aWinPos[0] + $aWinPos[2]) Or ($aMousePos[1] < $aWinPos[1] Or $aMousePos[1] > $aWinPos[1] + $aWinPos[3]) Then $bMouseOver = False Else $bMouseOver = True EndIf Return $bMouseOver EndFunc ;==>_MouseIsOverHWnd duzers, Xandy and Synapsee 3 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now