HansH Posted August 22, 2005 Posted August 22, 2005 Hi,I was missing a simple way for a general way to define onfocus and onblur functions on a control. Therefore I made a small UDF library which does this.This zipfile http://www.autoitscript.com/fileman/users/HansH/GuiFocus.zip contains the include file and an example.Just put the GuiFocus.au3 file in the include directory and test it with the example.Suggestions for improvement are always welcome.Hans------A bug is an undocumented feature. A bug becomes a feature by documenting it.
Michel Claveau Posted August 23, 2005 Posted August 23, 2005 Very useful; and it's also OK with button... And it's OK, with Alt-Tab. etc. Thanks.
Michel Claveau Posted August 23, 2005 Posted August 23, 2005 Re Just a little suggestion : Add, in the same function, the (mouse)-click. Like : _GuiFocusDefine($Gui, $GuiObj, "F_focus", "F_onblur","F_click") Good night.
HansH Posted August 24, 2005 Author Posted August 24, 2005 Just a little suggestion : Add, in the same function, the (mouse)-click.Like : _GuiFocusDefine($Gui, $GuiObj, "F_focus", "F_onblur","F_click")Michel, why should I add a mouseclick.When you click on a control, that control his onfocus will be triggered.Or do you want different functions activated when you click on a control ?Problem is that now only the classnames of the controls are saved, which is not enough I think to check the mouseclicklet me nowHans
Michel Claveau Posted August 25, 2005 Posted August 25, 2005 Hi ! Just a little example : Label (text), has no focus, but can do "clickable". sorry for my bad english
jdickens Posted August 25, 2005 Posted August 25, 2005 I am working on this issue just now.You may want to look at this previous implementation. A different approach, and perhaps more limitted:http://www.autoitscript.com/forum/index.ph...240entry58240J If I am too verbose, just say so. You don't need to run on and on.
HansH Posted August 25, 2005 Author Posted August 25, 2005 Just a little example : Label (text), has no focus, but can do "clickable".Michel, that is a tricky one, official it doesnot get focus and you could trap that by just<{POST_SNAPBACK}>$LABEL = GUICtrlCreateLabel("label", 15, 85, 40, 20 ) While 1 $msg = GUIGetMsg() _GuiFocusCheck($Gui) if $msg = $GUI_EVENT_CLOSE then ExitLoop if $msg = $LABEL then MsgBox(64,"Label", "clicked",2); WEndSo why do you want to click on a label, or are you using it for instance as a hyperlink ?The only thing I perhaps can do in the _GuiFocusCheck is to trigger the onblur of the current control.Or make seperate functions for onblur and onfocus which you can use to force a check when a label is activated, for instance:$LABEL = GUICtrlCreateLabel("label", 15, 85, 40, 20 ) While 1 $msg = GUIGetMsg() _GuiFocusCheck($Gui) if $msg = $GUI_EVENT_CLOSE then ExitLoop if $msg = $LABEL then _GuiFocus_onblur() ; force onblur check on current control if not @error then MsgBox(64,"Label", "clicked",2); endif WEndThe last one has my preference.Will this solve your problem ?Hans
HansH Posted August 27, 2005 Author Posted August 27, 2005 I am working on this issue just now.You may want to look at this previous implementation. A different approach, and perhaps more limitted:http://www.autoitscript.com/forum/index.ph...240entry58240J<{POST_SNAPBACK}>J,Yes, I looked at it. I'm saving the classname with the definition of the function for the control and checking in the loop if the current classname changes.Your doing an extra dll call in the loop to get an autoit controlid from itWell it saves some cpucycles by checking only the classname changes (no extra controlgetHandle and dllcall)Have to think if I can use this piece for passing the controlid to the user function, so you can define 1 onfocus or onblur function which get the controlid passed and the user can check what he wants to doperhaps something like:$GUI = GuiCreate("Has focus:") $one = GuiCtrlCreateButton("ok", 10, 10, 100, 50) $two = GuiCtrlCreateButton("cancel", 10, 110, 100, 50) $three = GuiCtrlCreateButton("maybe", 10, 210, 100, 50) GuiSetState() do $msg = GuiGetMsg() ; _GuiFocusCheck ( onblurfunc, onfocusFunc (default=onblurfunc)) _GuiFocusCheck("DOcheck") until $msg = $GUI_EVENT_CLOSE Func DOcheck($h_controlid, $s_type) ; type="onblur" or " onfocus" select case $h_controlid = $one ; do something case $h_controlid = $three ; do something EndSelect EndFuncThat would save the define of the focusfunctions and storages of that.GuiFocuscheck will do 2 calls to the given functions for each focus change.Thats what you were meaning ?But then I also have to think of a solution what michael said about a label I will make a new version based on this and we can try it out.Hans
HansH Posted August 27, 2005 Author Posted August 27, 2005 _GuiFocusCheck("DOcheck")Func DOcheck($h_controlid, $s_type) ; type="onblur" or " onfocus"J,it doesnot work this way.The call function does not support variable passingSo I am back to my original design.Hans
jdickens Posted August 29, 2005 Posted August 29, 2005 I suggested it for your interest and for everyone's comparison. Thanks for looking into it. J If I am too verbose, just say so. You don't need to run on and on.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now