Jump to content

GuiFocus UDF library


HansH
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

 

  _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

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