Jump to content
Sign in to follow this  
ShadowElf

How to detect focus lost event

Recommended Posts

ShadowElf

I want to detect a focus lost event. pls help

#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 258, 155, 238, 143)
$Combo1 = GUICtrlCreateCombo("Combo1", 24, 16, 217, 25)

!!!oneventfocuslost(call loss() function)!!!

$Input1 = GUICtrlCreateInput("Input1", 24, 48, 217, 21)
GUISetState(@SW_SHOW)
Func loss()
    MsgBox(-1, "test", "test")
EndFunc
While 1
Sleep(100)
WEnd

I like IT: php, mysql, codeingiter, css, jquery and AUTOIT

Share this post


Link to post
Share on other sites
funkey

Maybe that way!?

I don't know the variable-names

Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 258, 155, 238, 143)
GUISetOnEvent(-3, "_Exit")
GUIRegisterMsg(0x0111, "_LostFocus") ;$WM_KILLFOCUS

Global $Combo1 = GUICtrlCreateCombo("Combo1", 24, 16, 217, 25)
Global $Input1 = GUICtrlCreateInput("Input1", 24, 48, 217, 21)

GUISetState(@SW_SHOW)

While 1
 Sleep(100000)
WEnd

Func _Exit()
 Exit
EndFunc

Func _LostFocus($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
  If $nID = $Combo1 And $nNotifyCode = 10 Then MsgBox(0,  "Info", "ComboBox1 lost focus!")
  If $nID = $Input1 And $nNotifyCode = 512 Then MsgBox(0,  "Info", "Input1 lost focus!")
EndFunc

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites
ShadowElf

thx,

but why

$nNotifyCode = 10 and $nNotifyCode = 512

if I have 10 inputs, how can I know what is the value of $nNotifyCode ?


I like IT: php, mysql, codeingiter, css, jquery and AUTOIT

Share this post


Link to post
Share on other sites
funkey

I don't know why, but I tested it. I even don't know why there is a difference between Input and Combo!?

But it works.

Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 258, 300)
GUISetOnEvent(-3, "_Exit")
GUIRegisterMsg(0x0111, "_LostFocus") ;$WM_KILLFOCUS

Global $aInput[10]

For $i = 0 To 9
 $aInput[$i] = GUICtrlCreateInput("Input_"&$i , 20, 20 + $i* 22, 217, 21)
Next

GUISetState(@SW_SHOW)

While 1
 Sleep(100000)
WEnd

Func _Exit()
 Exit
EndFunc

Func _LostFocus($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
 If $nNotifyCode = 512 Then
  For $j = 0 To 9
   If $nID = $aInput[$j] Then MsgBox(0,  "Info", "Input" & $j & " lost focus!")
  Next
 EndIf  
EndFunc

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites
ShadowElf

and you know any other values for $nNotifyCode ?

for example buttons, list, etc?


I like IT: php, mysql, codeingiter, css, jquery and AUTOIT

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.