Jump to content
Sign in to follow this  
HansH

GuiFocus UDF library

Recommended Posts

HansH

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.

Share this post


Link to post
Share on other sites
Michel Claveau

Very useful; and it's also OK with button...

And it's OK, with Alt-Tab.

etc.

Thanks.

Share this post


Link to post
Share on other sites
Michel Claveau

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.

Share this post


Link to post
Share on other sites
HansH

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 mouseclick

let me now

Hans

Share this post


Link to post
Share on other sites
Michel Claveau

Hi !

Just a little example : Label (text), has no focus, but can do "clickable".

:whistle: sorry for my bad english :dance:

Share this post


Link to post
Share on other sites
HansH

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);
WEnd

So 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
WEnd

The last one has my preference.

Will this solve your problem ?

Hans

Share this post


Link to post
Share on other sites
HansH

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

J

<{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 it

Well 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 do

perhaps 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
EndFunc

That 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 :whistle:

I will make a new version based on this and we can try it out.

Hans

Share this post


Link to post
Share on other sites
HansH

 

  _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 passing

So I am back to my original design.

Hans

Share this post


Link to post
Share on other sites
jdickens

I suggested it for your interest and for everyone's comparison.

Thanks for looking into it. :whistle:

J


If I am too verbose, just say so. You don't need to run on and on.

Share this post


Link to post
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
Sign in to follow this  

×