Jump to content

Range of value?


OliverA
 Share

Recommended Posts

Hi forum,

I have searched, maybe not with the correct word, and i don't have find anything

I wanto to use MouseGetPos() for determinate if the mouse cursor is inside or outside the GUI.

Example:

My Gui is 500 x 200 at the center with -1 -1

My desktop is 800 x 600

So if Mouse X is in a range from > 150 but < 650 and the Mouse Y is etc. is inside GUI

And the same if it is outside

I'm not very good in math and i don't know if this is correct approach, i want to make this with $var and using a simple DLL call like:

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $GUI, "int", 500, "long", 0x00080000)
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $GUI, "int", 500, "long", 0x00090000)

I have make this but is wrong

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
Global $DesktopWidth = _WinAPI_GetSystemMetrics(78)
Global $DesktopHeight = _WinAPI_GetSystemMetrics(79)
Global $Fade = False
$Number_Element = 4
$GUI_Height = 100
$GUI_Width = $GUI_Height * $Number_Element
$GUIx = (@DesktopWidth / 2) - $GUI_Width / 2
$GUIy = -10
$hGUI = GUICreate("", $GUI_Width, $GUI_Height, $GUIx, $GUIy, BitOR($WS_POPUP, $WS_SYSMENU))
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
$pos = MouseGetPos()
Select
     Case $nMsg = $GUI_EVENT_CLOSE
         Exit
     Case $pos[0] "???" And Not $Fade
         $Fade = True
         DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI, "int", 500, "long", 0x00080000)
     Case $pos[0] "???" And $Fade
         $Fade = False
         DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI, "int", 500, "long", 0x00090000)
EndSelect
WEnd

a little help? :D

Edited by OliverA

I'M QUIT FROM THIS FORUM!

It was fun until it lasted, hope on my future way i can't find people that offend without any reason ( i was called lazy and parasitic, and everyone agreed...United we stand, divided we fall ) just for fun because don't have anything to do in the life, without knowing anything about the person who write, noone forced to post, noone forced to help.

From the top of the from their very great superiority they not go down to my level, that people can not spread the knowledge but you have to learn by yourself.

In what way? It's easy...just search on google

For that people, wish you the best way,

Oliver Astone

Link to comment
Share on other sites

  • Moderators

OliverA,

This seems to work - give it a try: ;)

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Global $Fade = False

$Number_Element = 4

$GUI_Height = 100
$GUI_Width = $GUI_Height * $Number_Element

$GUIx = (@DesktopWidth - $GUI_Width) / 2
$GUIy = -10

$hGUI = GUICreate("", $GUI_Width, $GUI_Height, $GUIx, $GUIy, $WS_POPUP)
GUISetBkColor(0xFF0000)
GUISetState(@SW_SHOW)

While 1
    ; Get mouse position
    $aMPos = MouseGetPos()
    ; Check y position first
    If $aMPos[1] < 100 Then
        ; Now x
        If $aMpos[0] > $GUIx And $aMPos[0] < $GUIx + $GUI_Width Then
            ; Now look at fade
            If $Fade Then
                $Fade = False
                DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI, "int", 500, "long", 0x00090000)
            Else
                $Fade = True
                DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI, "int", 500, "long", 0x00080000)
            EndIf
        EndIf
    EndIf
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
    EndSwitch
WEnd

Please ask if you have any questions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

No Melba, not work as aspacted :(

Two Problems:

1) When the mouse is inside the gui, the gui flashing, like disappear, appear, disappear, appear etc., if you want i'll make a video

2) The gui disappear when the mouse is inside, but i'd like the opposite. So:

Mouse inside the GUI = GUI visible

Mouse outside the GUI = GUI not visible

A sort of fade between the two method, i think that DLLCall is correct

Thanks for your help :D

Edited by OliverA

I'M QUIT FROM THIS FORUM!

It was fun until it lasted, hope on my future way i can't find people that offend without any reason ( i was called lazy and parasitic, and everyone agreed...United we stand, divided we fall ) just for fun because don't have anything to do in the life, without knowing anything about the person who write, noone forced to post, noone forced to help.

From the top of the from their very great superiority they not go down to my level, that people can not spread the knowledge but you have to learn by yourself.

In what way? It's easy...just search on google

For that people, wish you the best way,

Oliver Astone

Link to comment
Share on other sites

  • Moderators

OliverA,

Then why not explain that at the beginning so I do not waste my time coding something which does not meet your requriements? :mad:

This should do what you want: :)

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Global $Fade = False

$Number_Element = 4

$GUI_Height = 100
$GUI_Width = $GUI_Height * $Number_Element

$GUIx = (@DesktopWidth - $GUI_Width) / 2
$GUIy = -10

$hGUI = GUICreate("", $GUI_Width, $GUI_Height, $GUIx, $GUIy, $WS_POPUP)
GUISetBkColor(0xFF0000)
GUISetState(@SW_SHOW)

While 1
    ; Get mouse position
    $aMPos = MouseGetPos()
    ; Check position
    If $aMPos[1] < 100 And $aMpos[0] > $GUIx And $aMPos[0] < $GUIx + $GUI_Width Then
        ; Now look at fade
        If $Fade Then
            $Fade = False
                DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI, "int", 500, "long", 0x00080000)
        EndIf
    Else
        $Fade = True
        DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI, "int", 500, "long", 0x00090000)
    EndIf
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
    EndSwitch
WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

we can modify M23 code so that the guishows when over mouse

If $aMPos[1] < 100 And $aMpos[0] > $GUIx And $aMPos[0] < $GUIx + $GUI_Width Then GUISetState(@SW_SHOW)

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Sorry Melba if i wasn't clear :(

Thanks, work fine :D

I'M QUIT FROM THIS FORUM!

It was fun until it lasted, hope on my future way i can't find people that offend without any reason ( i was called lazy and parasitic, and everyone agreed...United we stand, divided we fall ) just for fun because don't have anything to do in the life, without knowing anything about the person who write, noone forced to post, noone forced to help.

From the top of the from their very great superiority they not go down to my level, that people can not spread the knowledge but you have to learn by yourself.

In what way? It's easy...just search on google

For that people, wish you the best way,

Oliver Astone

Link to comment
Share on other sites

I found this thread, , which I updated a little resulting in this:

#include <APIConstants.au3>
#include <WindowsConstants.au3>

Opt("MouseCoordMode", 2) ;
Global $bInBounds = True

Global $hGui = GUICreate('')
GUISetState()

Global $sTrackMouseEvent = DllStructCreate('dword;dword;hwnd;dword') ; Creating TRACKMOUSEEVENT Structure for TME_LEAVE
Global $sTME_size = DllStructGetSize($sTrackMouseEvent)  ; getting size of structure - need for 1st argument
DllStructSetData($sTrackMouseEvent, 1, $sTME_size) ; size of structure
DllStructSetData($sTrackMouseEvent, 2, $TME_LEAVE) ; TME_LEAVE
DllStructSetData($sTrackMouseEvent, 3, $hGui) ; HWND of our GUI
DllStructSetData($sTrackMouseEvent, 4, 0xFFFFFFFF) ; default hover timeout
Global $sTME_POINTER = DllStructGetPtr($sTrackMouseEvent)

MouseMove(1, 1, 0) ; ensure mouse is in window
DllCall('user32.dll', 'bool', 'TrackMouseEvent', 'ptr', $sTME_POINTER) ; start TME_LEAVE tracking

GUIRegisterMsg($WM_MOUSEMOVE, '__wm_mousemove')
GUIRegisterMsg($WM_MOUSELEAVE, '__wm_mouseleave')

;===================================================================================================================================
While 1
    $msg = GuiGetMsg()
    If $msg = -3 then ExitLoop
    Tooltip($bInBounds)
    Sleep(10)
WEnd
;===================================================================================================================================
Func __wm_mouseleave($hwnd, $msg, $wParam, $lParam) ; exiting window
    $bInBounds = False
    beep(750,10)
EndFunc

Func __wm_mousemove($hwnd, $msg, $wParam, $lParam) ; entering window
    If $bInBounds = False Then
        $bInBounds = True
     DllCall('user32.dll', 'bool', 'TrackMouseEvent', 'ptr', $sTME_POINTER) ; restart TME_LEAVE tracking
     beep(800,10)
    EndIF
EndFunc

It doesn't care what size your GUI is, or where on the screen you may have dragged it.

Edit: Run with beta Autoit, the production APIConstants.au3 include has bugs.

Edited by Spiff59
Link to comment
Share on other sites

  • Moderators

Spiff59,

Nice find! :thumbsup:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

You will need to add a few lines of code to check for the NC area

#include <APIConstants.au3>
#include <WindowsConstants.au3>

Opt("MouseCoordMode", 2) ;
Global $bInBounds = True

Global $hGui = GUICreate('')
GUISetState()

Global $sTrackMouseEvent = DllStructCreate('dword;dword;hwnd;dword') ; Creating TRACKMOUSEEVENT Structure for TME_LEAVE
Global $sTME_size = DllStructGetSize($sTrackMouseEvent) ; getting size of structure - need for 1st argument
DllStructSetData($sTrackMouseEvent, 1, $sTME_size) ; size of structure
DllStructSetData($sTrackMouseEvent, 2, $TME_LEAVE) ; TME_LEAVE
DllStructSetData($sTrackMouseEvent, 3, $hGui) ; HWND of our GUI
DllStructSetData($sTrackMouseEvent, 4, 0xFFFFFFFF) ; default hover timeout
Global $sTME_POINTER = DllStructGetPtr($sTrackMouseEvent)

MouseMove(1, 1, 0) ; ensure mouse is in window
DllCall('user32.dll', 'bool', 'TrackMouseEvent', 'ptr', $sTME_POINTER) ; start TME_LEAVE tracking

GUIRegisterMsg($WM_NCMOUSEMOVE, '__wm_mousemove')
GUIRegisterMsg($WM_MOUSEMOVE, '__wm_mousemove')
GUIRegisterMsg($WM_MOUSELEAVE, '__wm_mouseleave')
GUIRegisterMsg($WM_NCMOUSELEAVE, '__wm_mouseleave')

;===================================================================================================================================
While 1
$msg = GUIGetMsg()
If $msg = -3 Then ExitLoop
ToolTip($bInBounds)
Sleep(10)
WEnd
;===================================================================================================================================
Func __wm_mouseleave($hwnd, $msg, $wParam, $lParam) ; exiting window
If $msg = $WM_NCMOUSELEAVE Then $bInBounds = False
Beep(750, 10)
EndFunc   ;==>__wm_mouseleave

Func __wm_mousemove($hwnd, $msg, $wParam, $lParam) ; entering window
If $bInBounds = False Then
$bInBounds = True
DllCall('user32.dll', 'bool', 'TrackMouseEvent', 'ptr', $sTME_POINTER) ; restart TME_LEAVE tracking
Beep(800, 10)
EndIf
EndFunc   ;==>__wm_mousemove

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Maybe i'm stupid, but i have installed the last beta from here:

Installer containing SciTE and all configuration files plus utilities.Update History. Definition files included: AutoIt v3.3.9.0 and BETA v3.3.9.4

But when i'm start the script i have the error:

ERROR: can't open include file <APIConstants.au3>.

#include <APIConstants.au3>

And he has right, i don't have any APIConstants.au3 file in the include directory, only AVIConstants

???

I'M QUIT FROM THIS FORUM!

It was fun until it lasted, hope on my future way i can't find people that offend without any reason ( i was called lazy and parasitic, and everyone agreed...United we stand, divided we fall ) just for fun because don't have anything to do in the life, without knowing anything about the person who write, noone forced to post, noone forced to help.

From the top of the from their very great superiority they not go down to my level, that people can not spread the knowledge but you have to learn by yourself.

In what way? It's easy...just search on google

For that people, wish you the best way,

Oliver Astone

Link to comment
Share on other sites

Work also without APIConstant ( check it out the line of code ) but i have a little problem:

#include <WindowsConstants.au3>
Opt("MouseCoordMode", 2) ;
Global $bInBounds = True
Global $hGui = GUICreate('')
GUISetState()
Global $sTrackMouseEvent = DllStructCreate('dword;dword;hwnd;dword') ; Creating TRACKMOUSEEVENT Structure for TME_LEAVE
Global $sTME_size = DllStructGetSize($sTrackMouseEvent) ; getting size of structure - need for 1st argument
DllStructSetData($sTrackMouseEvent, 1, $sTME_size) ; size of structure
DllStructSetData($sTrackMouseEvent, 2, 0x00000002) ; TME_LEAVE ---> Change this line!!!!!!!!!!!!!
DllStructSetData($sTrackMouseEvent, 3, $hGui) ; HWND of our GUI
DllStructSetData($sTrackMouseEvent, 4, 0xFFFFFFFF) ; default hover timeout
Global $sTME_POINTER = DllStructGetPtr($sTrackMouseEvent)
MouseMove(1, 1, 0) ; ensure mouse is in window
DllCall('user32.dll', 'bool', 'TrackMouseEvent', 'ptr', $sTME_POINTER) ; start TME_LEAVE tracking
GUIRegisterMsg($WM_NCMOUSEMOVE, '__wm_mousemove')
GUIRegisterMsg($WM_MOUSEMOVE, '__wm_mousemove')
GUIRegisterMsg($WM_MOUSELEAVE, '__wm_mouseleave')
GUIRegisterMsg($WM_NCMOUSELEAVE, '__wm_mouseleave')
;===================================================================================================================================
While 1
$msg = GUIGetMsg()
If $msg = -3 Then ExitLoop
ToolTip($bInBounds)
Sleep(10)
WEnd
;===================================================================================================================================
Func __wm_mouseleave($hwnd, $msg, $wParam, $lParam) ; exiting window
If $msg = $WM_NCMOUSELEAVE Then $bInBounds = False
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGui, "int", 500, "long", 0x00090000)
EndFunc ;==>__wm_mouseleave
Func __wm_mousemove($hwnd, $msg, $wParam, $lParam) ; entering window
If $bInBounds = False Then
DllCall('user32.dll', 'bool', 'TrackMouseEvent', 'ptr', $sTME_POINTER) ; restart TME_LEAVE tracking
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGui, "int", 500, "long", 0x00080000)
$bInBounds = True
EndIf
EndFunc ;==>__wm_mousemove

If the GUI disappear no more come back :D

Solution?

Edited by OliverA

I'M QUIT FROM THIS FORUM!

It was fun until it lasted, hope on my future way i can't find people that offend without any reason ( i was called lazy and parasitic, and everyone agreed...United we stand, divided we fall ) just for fun because don't have anything to do in the life, without knowing anything about the person who write, noone forced to post, noone forced to help.

From the top of the from their very great superiority they not go down to my level, that people can not spread the knowledge but you have to learn by yourself.

In what way? It's easy...just search on google

For that people, wish you the best way,

Oliver Astone

Link to comment
Share on other sites

Bump :)

I'M QUIT FROM THIS FORUM!

It was fun until it lasted, hope on my future way i can't find people that offend without any reason ( i was called lazy and parasitic, and everyone agreed...United we stand, divided we fall ) just for fun because don't have anything to do in the life, without knowing anything about the person who write, noone forced to post, noone forced to help.

From the top of the from their very great superiority they not go down to my level, that people can not spread the knowledge but you have to learn by yourself.

In what way? It's easy...just search on google

For that people, wish you the best way,

Oliver Astone

Link to comment
Share on other sites

Sorry but it wont work this way,

the message wont be posted to the GUI until it captures the mouse movement.

And because the GUI is hidden, the message will never be posted again

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

  • 4 weeks later...

Spiff59,

Nice find! :thumbsup:

M23

Not so nice :)

If you add some controls inside the gui

#include <APIConstants.au3>
#include <WindowsConstants.au3>

Opt("MouseCoordMode", 2) ;
Global $bInBounds = True

Global $hGui = GUICreate('')
$exit = GuiCtrlCreateButton("exit", 150, 100, 60, 25)
GUISetState()

Global $sTrackMouseEvent = DllStructCreate('dword;dword;hwnd;dword') ; Creating TRACKMOUSEEVENT Structure for TME_LEAVE
Global $sTME_size = DllStructGetSize($sTrackMouseEvent) ; getting size of structure - need for 1st argument
DllStructSetData($sTrackMouseEvent, 1, $sTME_size) ; size of structure
DllStructSetData($sTrackMouseEvent, 2, $TME_LEAVE) ; TME_LEAVE
DllStructSetData($sTrackMouseEvent, 3, $hGui) ; HWND of our GUI
DllStructSetData($sTrackMouseEvent, 4, 0xFFFFFFFF) ; default hover timeout
Global $sTME_POINTER = DllStructGetPtr($sTrackMouseEvent)

MouseMove(1, 1, 0) ; ensure mouse is in window
DllCall('user32.dll', 'bool', 'TrackMouseEvent', 'ptr', $sTME_POINTER) ; start TME_LEAVE tracking

GUIRegisterMsg($WM_MOUSEMOVE, '__wm_mousemove')
GUIRegisterMsg($WM_MOUSELEAVE, '__wm_mouseleave')

;===================================================================================================================================
While 1
$msg = GuiGetMsg()
If $msg = -3 or $msg = $exit then ExitLoop
Tooltip($bInBounds)
Sleep(10)
WEnd
;===================================================================================================================================
Func __wm_mouseleave($hwnd, $msg, $wParam, $lParam) ; exiting window
$bInBounds = False
beep(750,10)
EndFunc

Func __wm_mousemove($hwnd, $msg, $wParam, $lParam) ; entering window
If $bInBounds = False Then
     $bInBounds = True
     DllCall('user32.dll', 'bool', 'TrackMouseEvent', 'ptr', $sTME_POINTER) ; restart TME_LEAVE tracking
     beep(800,10)
EndIF
EndFunc
then the WM_MOUSELEAVE message fires off when the pointer hovers these controls, this makes the mouseleave feature practically unusable

But if there is a way to avoid this problem and go on using GuiRegisterMsg (instead of looping a MouseGetPos) then I'll grab it immediately :)

Edited by mikell
Link to comment
Share on other sites

Something like this here?

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
$hGUI = GUICreate("Test", 640, 480, -1, -1, Default, $WS_EX_TOPMOST)
GUISetState()


Global Const    $AW_HOR_POSITIVE = 0x00000001, $AW_HOR_NEGATIVE = 0x00000002, $AW_VER_POSITIVE = 0x00000004, $AW_VER_NEGATIVE = 0x00000008, _
                $AW_CENTER = 0x00000010, $AW_HIDE = 0x00010000, $AW_ACTIVATE = 0x00020000, $AW_SLIDE = 0x00040000, $AW_BLEND = 0x00080000
Global $aWinPos, $a
AdlibRegister("Check", 50)

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            AdlibUnRegister()
            GUIDelete()
            Exit
    EndSwitch
Until False

Func Check()
    Local Static $b1 = False, $b2 = False
    $aWinPos = WinGetPos($hGUI)
    Switch _WinAPI_PtInRectEx(MouseGetPos(0), MouseGetPos(1), $aWinPos[0], $aWinPos[1], $aWinPos[2], $aWinPos[3])
        Case True
            If Not $b1 Then
                DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI, "int", 500, "long", $AW_BLEND)
                $b1 = True
                $b2 = False
            EndIf
        Case False
            If Not $b2 Then
                DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI, "int", 500, "long", $AW_BLEND + $AW_HIDE)
                $b2 = True
                $b1 = False
            EndIf
    EndSwitch
EndFunc

Func _WinAPI_PtInRectEx($iX, $iY, $iLeft, $iTop, $iWidth, $iHeight)
    Local $aResult, $tagREC = "int Left;int Top;int Right;int Bottom"
    Local $tRect = DllStructCreate($tagREC)
    DllStructSetData($tRect, "Left", $iLeft)
    DllStructSetData($tRect, "Top", $iTop)
    DllStructSetData($tRect, "Right", $iLeft + $iWidth)
    DllStructSetData($tRect, "Bottom", $iTop + $iHeight)
    $aResult = DllCall("User32.dll", "int", "PtInRect", "ptr", DllStructGetPtr($tRect), "int", $iX, "int", $iY)
    Return $aResult[0] <> 0
EndFunc

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

The disadvantage is when you loose the focus and GUI is not activated anymore than you cannot get back the GUI.

Possibilities: use a hotkey to activate GUI, find a way to show GUI in taskbar although it is faded out or ...

Have fun.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I thought the 'If Winactive' was a joke, after having lost the gui deep in the desktop

The winapi way is not so different than this simpler one (the same as Melba23 did)

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
Opt("GuiOnEventMode", 1)
Opt("MouseCoordMode", 2)
Global Const $AW_HOR_POSITIVE = 0x00000001, $AW_HOR_NEGATIVE = 0x00000002, $AW_VER_POSITIVE = 0x00000004, $AW_VER_NEGATIVE = 0x00000008, _
             $AW_CENTER = 0x00000010, $AW_HIDE = 0x00010000, $AW_ACTIVATE = 0x00020000, $AW_SLIDE = 0x00040000, $AW_BLEND = 0x00080000

Global $hGUI = GUICreate("", 300, 300, -1, -1, $WS_POPUP)
GuiCtrlCreatePic(StringRegExpReplace(@Autoitexe, '(.+)\\[^\\]+', "$1") & "\Examples\GUI\msoobe.jpg", 0, 0, 300, 300)
GUICtrlSetState(-1, $GUI_DISABLE)
$exit = GuiCtrlCreateButton("exit", 150, 100, 60, 25)
GUICtrlSetOnEvent(-1, "_exit")
GUISetState()

AdlibRegister("_test", 50)

While 1
Sleep(10)
Wend

;=======================
Func _test()
Static $in = False
Local $MP = MouseGetPos()
Local $WP = WinGetPos($hGUI)
If $MP[0]<0 or $MP[0]>$WP[2] or $MP[1]<0 or $MP[1]>$WP[3] Then
If $in = True Then
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI, "int", 500, "long", $AW_BLEND + $AW_HIDE)
$in = False
EndIf
Else
If $in = False Then
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI, "int", 500, "long", $AW_BLEND)
$in = True
EndIf
EndIf
EndFunc

Func _exit()
Exit
EndFunc
Edited by mikell
Link to comment
Share on other sites

Probably the function _WinAPI_PtInRectEx() is doing the same. Anyway, it was a fast hack and a proof of concept.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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