Jump to content

Simple and Stupid Control Hover UDF


binhnx
 Share

Recommended Posts

Nice! You have some examples to provide us?

SSControlHover_Register($idCtrl, $aIdAttachedCtrl, _
                $fnNormalCb, $vNormalData, $fnHoverCb, $vHoverData, $fnActiveCb, $vActiveData)

Something like popular the sentences below

; #FUNCTION# ====================================================================================================================
; Name ..........: SSControlHover_Register
; Description ...:
; Syntax ........: SSControlHover_Register($idCtrl, $aIdAttachedCtrl, $fnNormalCb, $vNormalData, $fnHoverCb, $vHoverData,
;                  $fnActiveCb, $vActiveData)
; Parameters ....: $idCtrl              - An integer value.
;                  $aIdAttachedCtrl     - An array of unknowns.
;                  $fnNormalCb          - A boolean value.
;                  $vNormalData         - A variant value.
;                  $fnHoverCb           - A boolean value.
;                  $vHoverData          - A variant value.
;                  $fnActiveCb          - A boolean value.
;                  $vActiveData         - A variant value.
; Return values .: None
; Author ........: Your Name
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================

JS

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

  • 3 weeks later...

Thank you very much! I used old UDF by Creator for making GUI "buttons" with Pic controls instead and I've noticed that the state fuctions returns too many results at a time. 'Cause of this I had not critical, but unpleasant blinks on my buttons when push and hold mouse button. Your UDF has solved all the problems. Can you clarify for me more detailed, what Data parameters (like $vClickData) do in your UDF?

P. S. There is a mistake in the _SSCtrlHover_Register function parameters' description. Last two names of parameters duplicating two others above.

Edited by pat4005
Link to comment
Share on other sites

@pat4005: I'm glad you are happy with my UDF :)

Sorry about the description, I wrote it at very late so I almost copy & paste & forget every thing :)

The $vClickData is a variable which then be pass to your $fnClickCb function callback, as like every other $v...Data in my UDF.

I planed to change the UDF a little more (using a fantastic method to store window and control infos so we don't need to loop to find the hover/active... control anymore, and a addtional UDF using the new handy Map feature in new AutoIt version). So I delay changing the description until I finish all the works (I'm too lazy  :sweating: ) (Currently I have no time for it :sweating: , but I will begin as soon as possible, so just wait  :thumbsup: )

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to comment
Share on other sites

binhnx, hi. Not so long ago I've had a problem with your UDF. When I point "-1" value as a first parameter in _SSCtrlHover_Register function then nothing works. I need to use a variable with control id instead. Also when I use _SSCtrlHover_Register function in multiple places in my program (in multiple windows) some of buttons work and some don't. Can you explain such behavior? Unpatiently wait for a new version of your UDF anyway!

Edited by pat4005
Link to comment
Share on other sites

At line 67:

$_aControlHoverData[$iIndex][0] = $idCtrl

I forgot to check $idCtrl = -1 at that point. You can modify it by adding this line after line 57 (before WinAPI GetAncestor() call)

If ($idCtrl=-1) Then $idCtrl = DllCall("user32.dll", "INT", "GetDlgCtrlID", "HWND", $hWnd)[0]

Sorry about that odd bug. I'll fix it in new version.

About the second bug, I haven't pointed out what wrong yet. Currently, my script only working with controls inside top-level GUI. If you use with nested GUI (child GUI(s) created by specified $WS_CHILD in GUICreate), you may get unexpected behavior. I'm not sure if that is your problem or not.

When I wrote the first line of the UDF, I decided that it should be much AutoIt as possible. So I try to reduce any WinAPI call (by DllCall), callback or timer function. But as time go by, I realize that it's impossible to write a good UDF without using many WinAPI functions :) This will solve a lot of problems with current version.

Good news: Will start writing today. You may have the new version tomorrow :D

Edited by binhnx

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to comment
Share on other sites

binhnx, your work is impressively REMARKABLE! Of course, I've already downloaded and tested new v3 UDF and it works perfectly great. To be more specific I've noticed speed improvement even by eye, my former problem was just miraculously solved and however blinking defect is still absent. Thank you very much!:thumbsup: But here is some "but". I found a little problem and I want to ask you some other questions:

1) Problem is that when I try to exit script containing your UDF functions using HotKeySet function for that, it crushes with an AutoIt big-don't-know-how-to-call-it error twice. Other times all works well.

 

2) Why don't you put your Assert function inside UDF?
3) Whether еру hover button effect must work when GUI is not active (just curious)?
4) Can you please post an example which will contain ready to use and clickable "button on hover" working scheme with images on controls (if I expressed my thoughts correctly)?
 
UPD: When compiled script crushes after any way to exit it  :ermm:.
Edited by pat4005
Link to comment
Share on other sites

@pat4005:

1. About the crash problem: I'll fix it later. But it's a good practice to manually delete all the GUI  (using GUIDelete) before using the Exit function.

2. Assert function is used for all my UDF so I think it's better to separate it to a different file. If you find it annoying and you only use this UDF, copy that function to main UDF file.

3. The event is delivered by Windows directly, so the hover function is called exactly when a control is on hover, and the normal function is called exactly when the mouse leave the control. Don't worry, it works no matter your GUI is activated or not. It only not work when your GUI is minimized or hidden (why do you need it to work when you can not put your mouse over the control :) ) It works when you need it and doesn't work when you don't need to save your CPU :) )

4. Later, later, later. I'll add a addition SSButtonHover UDF. Now I'm messing with another project :D

Edit: Assert is intended to use in dev. It's only mission is check for something that may cause if you write something careless. So, if you're sure all things you wrote a right: check error, ensure the variable type you specified is match with the expected type... so you definitely safe to remove all the assert statement from my UDF.

PS: Thank you for your feedback, it helps me a lot to improve my UDF quality.

Edited by binhnx

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 years later...
  • Developers
2 hours ago, ura said:

About the crash problem

Which crash problem?  You do realize you're posting in a 3 years old thread?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

8 hours ago, Jos said:

哪个崩溃的问题?你确实意识到你在一个3年的线程发布?

乔斯

Hi, Jos.

1) Compile and run in the exit when there will be two prompt error (The reason seems to be that the registered subclasses have not been removed)

2) I need this udf, and in improving this UDF, help me:unsure:

 

Link to comment
Share on other sites

It's true that the crash during script end when the script is run as 64-bit code is caused by the subclasses have not been removed.

You can remove the subclasses in the example in the first post in this way:

#AutoIt3Wrapper_UseX64=y

#include "SSCtrlHover_v3.au3"

GUICreate(@AutoItVersion)
$idLbl1 = GUICtrlCreateLabel("Label 1", 5, 5)
SSCtrlHover_Register($idLbl1, "FnNormal", 0, "FnHover", 0, "FnActive", 0, "FnClick", 0)
$idLbl2 =GUICtrlCreateLabel("Label 2", 5, 35)
SSCtrlHover_Register($idLbl2, "FnNormal", 0, "FnHover", 0, "FnActive", 0, "FnClick", 5)
GUISetState()

While GUIGetMsg() <> -3
  Sleep(10)
WEnd

_WinAPI_RemoveWindowSubclass(GUICtrlGetHandle($idLbl1), $__SSCTRLHOVER_PSUBCLASSEXE, GUICtrlGetHandle($idLbl1))
_WinAPI_RemoveWindowSubclass(GUICtrlGetHandle($idLbl2), $__SSCTRLHOVER_PSUBCLASSEXE, GUICtrlGetHandle($idLbl2))

Func FnNormal($idCtrl, $hWnd, $vData)
  ConsoleWrite(@CRLF & "Normal/Leave " & $idCtrl)
EndFunc

Func FnHover($idCtrl, $hWnd, $vData)
  ConsoleWrite(@CRLF & "Hover " & $idCtrl)
EndFunc

Func FnActive($idCtrl, $hWnd, $vData)
  ConsoleWrite(@CRLF & "Active " & $idCtrl)
EndFunc

Func FnClick($idCtrl, $hWnd, $vData)
  ConsoleWrite(@CRLF & "CLICK! " & $idCtrl & " - " & $hWnd & " - " & $vData)
EndFunc

 

Link to comment
Share on other sites

  • 1 month later...
On 2017-4-19 at 0:03 AM, LarsJ said:

确实,当脚本运行时,脚本中的崩溃是64位代码由子类引起的还没有被删除。

您可以通过以下方式删除第一篇文章中示例中的子类:

#AutoIt3Wrapper_UseX64 = Y

#include “SSCtrlHover_v3.au3

GUICreate@AutoItVersion$ idLbl1  =  GUICtrlCreateLabel(“标记1” , 55 ) 
SSCtrlHover _寄存器($ idLbl1 , “FnNormal” , 0 , “FnHover” , 0 , “FnActive” , 0 , “FnClick” , 0$ idLbl2  = GUICtrlCreateLabel(“Label 2” , 535 ) 
SSCtrlHover _ Register($ idLbl2 , “FnNormal” , 0 , “FnHover” , 0 , “FnActive” , 0 , “FnClick” , 5GUISetState()

而 GUIGetMsg() <>  - 3 
  睡眠(10WEnd

_WinAPI_RemoveWindowSubclass(GUICtrlGetHandle$ idLbl1 ), $ __ SSCTRLHOVER_PSUBCLASSEXE , GUICtrlGetHandle$ idLbl1 ))
_WinAPI_RemoveWindowSubclass(GUICtrlGetHandle$ idLbl2 ), $ __ SSCTRLHOVER_PSUBCLASSEXE , GUICtrlGetHandle$ idLbl2 ))

Func FnNormal($ idCtrl , $ hWnd$ vData )
  ConsoleWrite@CRLF & “Normal / Leave”  & $ idCtrl )
EndFunc

Func FnHover($ idCtrl , $ hWnd$ vData )
  ConsoleWrite@CRLF & “Hover”  & $ idCtrl )
EndFunc

Func FnActive($ idCtrl , $ hWnd$ vData )
  ConsoleWrite@CRLF & “Active”  & $ idCtrl )
EndFunc

Func FnClick($ idCtrl , $ hWnd$ vData )
  ConsoleWrite@CRLF & “CLICK!”  & $ idCtrl  & “ - ”  & $ hWnd  & “ - ”  & $ vData )
EndFunc

 

How to integrate into the UDF?

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

×
×
  • Create New...