Jump to content

is mouse over GUI?


John117
 Share

Recommended Posts

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 by Hatcheda
Link to comment
Share on other sites

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)

NEWHeader1.png

Link to comment
Share on other sites

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)

NEWHeader1.png

Link to comment
Share on other sites

THanks - I'll work that in. Take a look at this :)

Global $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

a little better

And 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_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

  • 8 years later...
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

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 by InunoTaishou
Link to comment
Share on other sites

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 by guiltyking
Link to comment
Share on other sites

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

 

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