Jump to content



Photo

GuiCtrlSetOnHover()?


  • Please log in to reply
13 replies to this topic

#1 Achilles

Achilles

    Achilles == Ichigo

  • Active Members
  • PipPipPipPipPipPip
  • 2,897 posts

Posted 22 September 2007 - 09:51 PM

I know many people (like Valuater and marfdaman) have made things for hovering over labels and whatever else... However I was wondering if it would be possible to someway have some sort of GuiCtrlSetOnHover(). Like it automatically performs a function when you hover, pretty much the exact same as GuiCtrlSetOnEvent except with hovering.

It seems inefficient to me to have a script constantly checking the mouse position to see if it's hovering, although it works great for me! However, I was just wondering if this would be at all possible.







#2 DirtDBaK

DirtDBaK

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 978 posts

Posted 05 October 2007 - 12:09 AM

there is a way to do so! Im not sure how but my buddy did it with the guigetcursorinfo()



But what is impoarant is this part
 $mouse=GUIGetCursorInfo()   if $mouse[4]=$CONTROL_ID then      Msgbox(0,"Your Hovering", "Over the control" )  Endif   if $mouse[4]<>$CONTROL_ID then      Msgbox(0,"Your Hovering", "not Over the control" )   Endif




This was pulled out of a program my buddy made
                $msg = GUIGetMsg()                 $mouse=GUIGetCursorInfo()                 while @error=0                     if $mouse[4]=$PU then GUICtrlSetimage( $PU, "PU2.BMP")                     if $mouse[4]<>$PU then GUICtrlSetimage( $PU, "PU.BMP")                     if $mouse[4]=$SUBMenu[0] then GUICtrlSetimage( $SUBMenu[0], "PU2.BMP")                     if $mouse[4]=$SUBMenu[1] then GUICtrlSetimage( $SUBMenu[1], "PU2.BMP")                     if $mouse[4]=$SUBMenu[2] then GUICtrlSetimage( $SUBMenu[2], "PU2.BMP")                     if $mouse[4]=$SUBMenu[3] then GUICtrlSetimage( $SUBMenu[3], "PU2.BMP")                     if $mouse[4]<>$SUBMenu[0] then GUICtrlSetimage( $SUBMenu[0], "PU.BMP")                     if $mouse[4]<>$SUBMenu[1] then GUICtrlSetimage( $SUBMenu[1], "PU.BMP")                     if $mouse[4]<>$SUBMenu[2] then GUICtrlSetimage( $SUBMenu[2], "PU.BMP")                     if $mouse[4]<>$SUBMenu[3] then GUICtrlSetimage( $SUBMenu[3], "PU.BMP")                     exitloop                 wend

What it did was it changed the picture if you were hovering over the control

Posted Image


#3 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,729 posts

Posted 05 October 2007 - 12:14 AM

I haven't checked in some time, but I believe there is a WM_MOUSEHOVER ... if that is true then you could use GUIRegisterMsg() and some custom mousegetpos/childgetwinfrompoint function. Would be interesting to see what you turn out.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.


#4 Siao

Siao

    RTFM, foo!

  • Active Members
  • PipPipPipPipPipPip
  • 937 posts

Posted 05 October 2007 - 01:37 AM

I haven't checked in some time, but I believe there is a WM_MOUSEHOVER ... if that is true then you could use GUIRegisterMsg() and some custom mousegetpos/childgetwinfrompoint function. Would be interesting to see what you turn out.

There is, and you could, but it's questionable if it's really worth it in the end... when GUIGetCursorInfo does it all for you.
You need to call TrackMouseEvent each time that message pops. If you want to be more efficient, you need to subclass the control to catch its WM_MOUSEHOVER messages, because trying to work out control hover using WM_MOUSEHOVER of the main window isn't all that different from polling GUIGetCursorInfo in your main loop.
I did some WM_MOUSELEAVE tracking in one of my AutoIt apps, to get when the mouse enters/leaves window, and it worked, but then I ditched whole concept for the sake of simplicity.
"be smart, drink your wine"

#5 therks

therks

    Witty quote

  • Active Members
  • PipPipPipPipPipPip
  • 2,163 posts

Posted 05 October 2007 - 01:38 AM

There is, but it looks a little more complicated than that...

The TrackMouseEvent function posts messages when the mouse pointer leaves a window or hovers over a window for a specified amount of time.
...
The mouse pointer is considered to be hovering when it stays within a specified rectangle for a specified period of time. Call SystemParametersInfo. and use the values SPI_GETMOUSEHOVERWIDTH, SPI_GETMOUSEHOVERHEIGHT, and SPI_GETMOUSEHOVERTIME to retrieve the size of the rectangle and the time.


So I'm not sure this is exactly what he's looking for.

#6 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,729 posts

Posted 05 October 2007 - 02:07 AM

There is, but it looks a little more complicated than that...
So I'm not sure this is exactly what he's looking for.

It would be WM_MOUSEMOVE...

And customizing "per" gui would be no problem using what I stated... the issue is making it a CallBack (now possible thanks to piccaso I believe) and being able to globally store all the options.

Personally, I wouldn't look forward to writing it to be universal... but it might be up your alley with what you were doing just recently http://www.autoitscript.com/forum/index.ph...c=53390&hl= ... I would think using Call() ... a few globals ... and a callback and you could make it universal with what I suggested...

*** Again, these are just thoughts, I haven't actually sat down to test any of it, but I'm fairly confident I could make it work with RegisterMsg() + a function to work on the WM_MOUSEMOVE with just my own GUI and knowing what was going to be called and what needed changing when called (<< That last part is where I stopped thinking :) )

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.


#7 Achilles

Achilles

    Achilles == Ichigo

  • Active Members
  • PipPipPipPipPipPip
  • 2,897 posts

Posted 05 October 2007 - 02:16 AM

@DBack: That is what I use currently. I was hoping for something that didn't require constant checking.

@The rest: What Smoke_N said sounds like a good option. Like the GuiRegisterMsg()... However, I would have NO idea whatsoever how to do this and I don't have time to learn :)

If anybody has time and gets it to work it would be sweet!

#8 corz

corz

    Prodigy

  • Active Members
  • PipPipPip
  • 164 posts

Posted 06 October 2007 - 08:45 AM

I use hovering extensively in my color pickin chooser. Check the source.

Once you get your head around the simple fact that Control ID's are just numbers (something the manual doesn't really nail - the GUIGetCursorInfo() page would be good), it's all quite easy to implement. Here's the main loop, whith a whole lotta hovering going on..

AutoIt         
    ; main loop..     ;     while not $do_quit             if $do_func <> "" then             Call($do_func)         endif         sleep(75)         local $mouse_info = GUIGetCursorInfo() ; help file page for this command needs a decent hover example!         ; in fact, *any* decent examples would be good.         if $mouse_info = 0 then             $left_window = true             cpc_UnSetHotKeys()         else             cpc_SetHotKeys()             if $super_mag and $left_window = true then ; back inside the gui                 cpc_SwitchOffSuperMag()             endif             $left_window = false         endif         if not IsArray($mouse_info) then continueloop ; outside gui         local $MousePos = MouseGetPos()         if not IsArray($MousePos) then continueloop         ; inside picker, grad, or mag (or dragable info label)..         if $mouse_info[4] = $pic_color_picker or $mouse_info[4] >= $info_dummy then             if $mouse_info[4] = $info_dummy or $mouse_info[4] = $label_colorwell then ; it's trivial to check which control you are hovering over                 GUISetCursor(9, 1, $gui_color)  ; feel free to use something like this for the GUIGetCursorInfo() manual page.                 continueloop                    ; no credit required! ;o)             endif                         GUISetCursor(3, 1, $gui_color) ; "+"             $cpc_live_color = StringRight(Hex(PixelGetColor($MousePos[0],$MousePos[1])), 6)             cpc_UpdateLiveColorBox()             ; hold down left mouse button for live effects..             if $live_luminance = $GUI_CHECKED or ce_IsPressed(01) then cpc_UpdateLumGrad($cpc_live_color)             if $live_mag = $GUI_CHECKED or ce_IsPressed(01) then cpc_UpdateMag()             if $live_hex = $GUI_CHECKED then                 if ce_IsPressed(10) then                     ToolTip(ConvertColorValue($cpc_live_color, $cpc_output_mode, $add_prefix), $MousePos[0]+2, $MousePos[1]+2)                 else                     ToolTip($cpc_live_color, $MousePos[0]+2, $MousePos[1]+2)                 endif             endif             $color_set = 1         elseif $super_mag then             cpc_UpdateMag()             GUISetCursor(3, 1, $gui_color)         else ; outside picker areas or window..             GUISetCursor()             ToolTip ("")             if $color_set = 1 then                 if $hold_live_color = $GUI_UNCHECKED then                     GUICtrlSetBkColor($label_live_color, "0x" & $cpc_my_color)                     if $live_luminance = $GUI_CHECKED then cpc_UpdateLumGrad($cpc_my_color)                 endif                 $color_set = 0             endif         endif     wend


;o)
(or
nothing is foolproof to the sufficiently talented fool..

#9 MikeOsdx

MikeOsdx

    Never trust a Monkey

  • Active Members
  • PipPipPipPipPipPip
  • 543 posts

Posted 11 October 2007 - 03:49 PM

I am really looking for a GuiCtrlSetOnHover also.

I have been using Xskin to do this but I have encountered a Major flaw with Xskin and all other hover scripts I have found.

If you have a combo box dropped down and displaying over a button and you select an item that is imediatly over the button, the button gets clicked.

It should be as simple as copying the GuiCtrlSetOnEvent code and just make a function that looks for a Mouseover command instead of a click.

Mike

Edited by MikeOsdx, 11 October 2007 - 03:50 PM.

Posted Image

#10 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,241 posts

Posted 14 October 2007 - 05:26 AM

Ok, i think i got it (thanks to SmOke_N for the ideas from his posts)...

Here is the standard method (Not work with Labels, inputs/edits and maybe more controls):

AutoIt         
;NOT WORK WITH LABEL, INPUT, OR EDIT CONTROL! #include <GuiConstants.au3> Global Const $WM_NOTIFY = 0x004E Global $HOVER_CONTROLS_ARRAY[1][1] GuiCreate("Test") GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") $Button = GUICtrlCreateButton("Button", 20, 40, 70, 20) GUICtrlSetOnHover($Button, "My_Hover_Func") $CheckBox = GUICtrlCreateCheckbox("CheckBox", 20, 80, 70, 20) GUICtrlSetOnHover($CheckBox, "My_Hover_Func") GUISetState() While 1     $Msg = GUIGetMsg()     Switch $Msg         Case -3             Exit     EndSwitch WEnd Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)     If UBound($HOVER_CONTROLS_ARRAY)-1 < 1 Then Return $GUI_RUNDEFMSG         Local $CursorInfo = GUIGetCursorInfo($hWndGUI)     If $CursorInfo[4] = 0 Then         Printf("No Hovered Controls")         Return $GUI_RUNDEFMSG     EndIf         For $i = 1 To $HOVER_CONTROLS_ARRAY[0][0]         If $HOVER_CONTROLS_ARRAY[$i][0] = GUICtrlGetHandle($CursorInfo[4]) Then             Call($HOVER_CONTROLS_ARRAY[$i][1], $CursorInfo[4])             ExitLoop         EndIf     Next     Return $GUI_RUNDEFMSG EndFunc Func GUICtrlSetOnHover($CtrlID, $FuncName)     Local $Ubound = UBound($HOVER_CONTROLS_ARRAY)     ReDim $HOVER_CONTROLS_ARRAY[$Ubound+1][2]     $HOVER_CONTROLS_ARRAY[$Ubound][0] = GUICtrlGetHandle($CtrlID)     $HOVER_CONTROLS_ARRAY[$Ubound][1] = $FuncName     $HOVER_CONTROLS_ARRAY[0][0] = $Ubound EndFunc Func My_Hover_Func($CtrlID)     Printf("Control " & $CtrlID & " [Data: " & GUICtrlRead($CtrlID, 1) & "] Is Now Hovered") EndFunc ;Debug Function Func Printf($Str, $Line=@ScriptLineNumber)     ConsoleWrite("!===========================================================" & @LF & _                 "+======================================================" & @LF & _                 "--> Script Line (" & $Line & "):" & @LF & "!" & @TAB & $Str & @LF & _                 "+======================================================" & @LF) EndFuncƒo݊÷ ØÆ²m謆‹¥vëXÃQ! 9Q!z·›ºØ­Á«,–Œ–+ex  ݅êފËax&¥”œ’g­†‡p¢¹0ŠØZ–X­†)äþ)'¶º%²+wöƦ¹Èi­çÞ­çfzØhu«­¢+؍¥¹±Õ‘”€™±Ðí±± …±±  …¬¹…Ô̙Ðì()±½‰…°€˜ŒÀÌØí!=YI} =9QI=1M}IIelÅulÅt)±½‰…°€˜ŒÀÌØíÁQ¥µ•ÉAɽŒ€ô}±± …±±  …¬ ™ÅÕ½Ðí 11  -AI= ™ÅÕ½Ð찀™ÅÕ½Ðí¡Ý¹íÕ¥¹ÐíÕ¥¹Ðí‘ݽɐ™ÅÕ½Ðì¤)±½‰…°€˜ŒÀÌØíÕ¥Q¥µ•È€ô±± …±° ™ÅÕ½ÐíÕ͕ÈÌȹ‘±°™ÅÕ½Ð찀™ÅÕ½ÐíÕ¥¹Ð™ÅÕ½Ð찀™ÅÕ½ÐíM•ÑQ¥µ•È™ÅÕ½Ð찀™ÅÕ½Ðí¡Ý¹™ÅÕ½Ð찀À°€™ÅÕ½ÐíÕ¥¹Ð™ÅÕ½Ð찀À°€™ÅÕ½Ðí¥¹Ð™ÅÕ½Ð찀ÄÀ°€™ÅÕ½ÐíÁÑșÅÕ½Ð찀˜ŒÀÌØíÁQ¥µ•ÉAɽŒ¤(˜ŒÀÌØíÕ¥Q¥µ•È€ô€˜ŒÀÌØíÕ¥Q¥µ•ÉlÁt()Õ¥ ɕ…Ñ” ™ÅÕ½ÐíU% ÑɱM•Ñ=¹!½Ù•ȁ5


The DllCallBack.au3 you can find here.
Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image 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 ProgramPosted Image UDFs: 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 UDFPosted Image 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 DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#11 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,241 posts

Posted 14 October 2007 - 06:10 AM

All:
Check this out :) - I made an UDF from it!
Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image 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 ProgramPosted Image UDFs: 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 UDFPosted Image 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 DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#12 corz

corz

    Prodigy

  • Active Members
  • PipPipPip
  • 164 posts

Posted 14 October 2007 - 11:48 PM

THIS IS ALREADY BUILT-IN TO AUTOIT!

local $MousePos = MouseGetPos() if $mouse_info[4] = $MyControl then     ; do something endif


I don't have the problem with activating controls under drop-downs, either.
Why all the complexity? Am I missing something?

;o)
(or
nothing is foolproof to the sufficiently talented fool..

#13 Achilles

Achilles

    Achilles == Ichigo

  • Active Members
  • PipPipPipPipPipPip
  • 2,897 posts

Posted 15 October 2007 - 12:03 AM

THIS IS ALREADY BUILT-IN TO AUTOIT!

local $MousePos = MouseGetPos() if $mouse_info[4] = $MyControl then     ; do something endif

I don't have the problem with activating controls under drop-downs, either.
Why all the complexity? Am I missing something?

;o)
(or

What you use requires the code to be constantly checking to see if something is hovered. The new was that MsCreator put together notifies you when you hover over something and immediately does a function.

For example... would you rather check every second to see if the time is 5:30 by looking at your watch or just set an alarms for 5:30?

#14 corz

corz

    Prodigy

  • Active Members
  • PipPipPip
  • 164 posts

Posted 16 October 2007 - 07:26 PM

I don't follow the analogy; *I* don't need to do anything! But surely *some* code needs to be constantly checking for the hover, and it's compact trivial to achieve inside any main loop. I just don't see the need to wrap this inside anything.

Though better examples in the manual would be good.

;o)
(or
nothing is foolproof to the sufficiently talented fool..




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users