Jump to content

check mouse if its in certain area


tomashen
 Share

Recommended Posts

i dont know how to search and i cant find anything like this ^^

but wat i wana do is

when mouse is hovered over button

then create another button at bottom of it and while its active keep checking if mouse cord is in that area if not then delete the button below :D

wat i got is

while $MOUSE_RECORD[0] > 154 & $MOUSE_RECORD[1] > 100
                $TEST=GUICtrlCreatePic("",0, 25, 154, 15)
                _ResourceSetImageToCtrl(-1, "APPLICATION1")
            WEnd
                GUICtrlDelete($TEST)

Proud of AutoIt Proud of MySelf :)

Link to comment
Share on other sites

  • Moderators

tomashen,

There are many ways to do this, butthis is probably the simplest: :oops:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hButton = GUICtrlCreateButton("Test", 10, 10, 80, 30)

$hPic = GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\mslogo.jpg", 10, 60, 200, 40)
GUICtrlSetState(-1, $GUI_HIDE)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; Check what is under the cursor
    $aCInfo = GUIGetCursorInfo()
    ; If it is the button
    If $aCinfo[4] = $hButton Then
        ; Check if picture is hidden
        If BitAnd(GUICtrlGetState($hPic), $GUI_HIDE) Then
            ; if so then show it
            GUICtrlSetState($hPic, $GUI_SHOW)
        EndIf
    ; If it is not the button
    Else
        ; Check if picture is showing
        If BitAnd(GUICtrlGetState($hPic), $GUI_SHOW) Then
            ; If so then hide it
            GUICtrlSetState($hPic, $GUI_HIDE)
        EndIf
    EndIf

WEnd

You need the slightly complicated hide/show code or you get a lot of flashing as the picture is constantly reshown. :rip:

All clear? :D

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

epic would of never tought of using

GuiGetCursorInfo()
thank you very much :D

and about hide/show haha i used

GuiCtrlDelete()
and that why sometimes i get flashings going on :oops:

thnx again

but uh , how can i make this to be like

the image would stay showen if mouse is hovered on the iamge too...like read mouse cord in certain area..if its not in the area then hide the image :/ im tring to figure it out but finding it rly hard lol

Edited by tomashen

Proud of AutoIt Proud of MySelf :)

Link to comment
Share on other sites

  • Moderators

tomashen,

This looks for the mouse in a defined area: :oops:

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

; Use Client Area coordinates - so we can use the same reference frame as the normal controls
Opt("MouseCoordMode", 2)

; Define the area
Global $iL = 10, $iT = 10, $iW = 200, $iH = 90

$hGUI = GUICreate("Test", 500, 500)

; This is just to show the are we are loking at - you do NOT need to for the code to work
GUICtrlCreateLabel("", $iL, $iT, $iW, $iH)
GUICtrlSetBkColor(-1, 0xFFCCCC)
GUICtrlSetState(-1, $GUI_DISABLE)

$hButton = GUICtrlCreateButton("Test", 10, 10, 80, 30)

$hPic = GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\mslogo.jpg", 10, 60, 200, 40)
GUICtrlSetState(-1, $GUI_HIDE)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    $aMPos = MouseGetPos()
    ; Is the mouse in the rectangle
    If _WinAPI_PtInRectEx($aMPos[0], $aMPos[1], $iL, $iT, $iL+ $iW, $iT + $iH) Then
        ; Check if picture is hidden
        If BitAnd(GUICtrlGetState($hPic), $GUI_HIDE) Then
            ; if so then show it
            GUICtrlSetState($hPic, $GUI_SHOW)
        EndIf
    ; If it is not the button
    Else
        ; Check if picture is showing
        If BitAnd(GUICtrlGetState($hPic), $GUI_SHOW) Then
            ; If so then hide it
            GUICtrlSetState($hPic, $GUI_HIDE)
        EndIf
    EndIf

WEnd

Func _WinAPI_PtInRectEx($iX, $iY, $iLeft, $iTop, $iRight, $iBottom)
    Local $aResult
    Local $tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, "Left", $iLeft)
    DllStructSetData($tRect, "Top", $iTop)
    DllStructSetData($tRect, "Right", $iRight)
    DllStructSetData($tRect, "Bottom", $iBottom)
    $aResult = DllCall("User32.dll", "int", "PtInRect", "ptr", DllStructGetPtr($tRect), "int", $iX, "int", $iY)
    If @error Then Return SetError(@error, 0, False)
    Return $aResult[0] <> 0
EndFunc  ;==>_WinAPI_PtInRectEx

As explained the code, you do not need the label - it is just there to show the extent of the area we examine. :rip:

Better? :D

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

  • Moderators

tomashen,

ild kiss u if i could

Just as well you cannot as I am sure my wife would not approve at all! :D

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

  • Moderators

tomashen,

(handshake) Thank you - glad I could help. :D

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

umm i keep getting this error if i Alt+Tab out of the app

(94) : ==> Subscript used with non-Array variable.:

If $CURSOR_GET_PLACE_ON_BUTTON[4] = $APPLICATIONS Then

If $CURSOR_GET_PLACE_ON_BUTTON^ ERROR

i dont get wats wrong lmao.. tryed putting $CURSOR_GET_PLACE_ON_BUTTON in global and in global const but still error

Proud of AutoIt Proud of MySelf :)

Link to comment
Share on other sites

  • Moderators

tomashen,

The GUI is no longer active when you use Alt-Tab and so you do not get a valid array returned from GUIGetCursorInfo. Just add some errorchecking like this :

If IsArray($CURSOR_GET_PLACE_ON_BUTTON) And $CURSOR_GET_PLACE_ON_BUTTON[4] = $APPLICATIONS Then

Now if no array is returned, the crash will not occur. :D

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

ah ill knw this the next time now :D thnx once more! :oops:

also is there a way to make the GUI work when its not active..

like um when its not active if i move my cursor on a button an image will appear so its like as if the gui is inactive but it still works.. like "sleep walking" :rip:

i was thinking of using "AlwaysOnTop" or sumtin like that but i doubt that would help

Proud of AutoIt Proud of MySelf :)

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