Alexman Posted December 4, 2007 Share Posted December 4, 2007 hi, i knew that we may handle window by usin' Title of it, but what to do if Title is dynamic? i also knew that window have static coords and would be in the same place all the time. what i want from it, when somethin' happens at this window, it takes a focus, how could i make some event each time on that "onfocus" ? is it real? thnx for attention Link to comment Share on other sites More sharing options...
jvanegmond Posted December 4, 2007 Share Posted December 4, 2007 (edited) You can get the active window hWnd by doing this: WinGetHandle("") So that may solve your problem that you have getting the Handle.. You should also loop to get the state of the window, so when it focuses you know because the state is different then last time.. This is an example that attaches to the active window... Opt("WinTitleMatchMode",2) $sHwnd = WinGetHandle("") MsgBox(0, "", "Attached program to: " & WinGetTitle($sHwnd) ) Dim $sVisible = BitAND(WinGetState($sHwnd),8) If @error Then Exit ; SciTE not found While 1 If BitAND(WinGetState($sHwnd),8) AND Not $sVisible Then onfocus() $sVisible = 1 ElseIf Not BitAND(WinGetState($sHwnd),8) AND $sVisible Then $sVisible = 0 EndIf Sleep(50) WEnd Func onfocus() MsgBox(0, "", "I just focused") EndFunc Edited December 4, 2007 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
Alexman Posted December 4, 2007 Author Share Posted December 4, 2007 thnx very much, look what i want to make, have an application where Text dynamically refreshes... i go to this app by Button IsPressed copy text to buffer and extract it to file, do u know how to make it automatic, if window focuses program automatically save text from app to file. expandcollapse popup#include <Misc.au3> #include <File.au3> $dll = DllOpen("user32.dll") Func onfocus() MsgBox(0, "", "I just focused") EndFunc Func get_Text() MouseClick("left", 50, 315, 1, 1) Send("{CTRLDOWN}") Send("{A DOWN}") Sleep(10) Send("{CTRLUP}") Send("{A UP}") Sleep(10) Send("{CTRLDOWN}") Send("{C DOWN}") Sleep(10) Send("{CTRLUP}") Send("{C UP}") Sleep(10) $buffer = clipget() _FileCreate ( "C:\test.txt" ) $file = FileOpen("C:\test.txt", 2) If $file = -1 Then MsgBox(0, "Error", "Unable to create|open file.") Exit EndIf FileWrite($file, $buffer) FileClose($file) EndFunc Func get_win_handle() Opt("WinTitleMatchMode",2) $sHwnd = WinGetHandle("") MsgBox(0, "", "Attached program to: " & WinGetTitle($sHwnd) ) Dim $sVisible = BitAND(WinGetState($sHwnd),8) If @error Then Exit If BitAND(WinGetState($sHwnd),8) AND Not $sVisible Then onfocus() $sVisible = 1 ElseIf Not BitAND(WinGetState($sHwnd),8) AND $sVisible Then $sVisible = 0 EndIf EndFunc While 1 If _IsPressed("23", $dll) Then get_Text() get_win_handle() EndIf If _IsPressed("22", $dll) Then ExitLoop EndIf If _IsPressed("21", $dll) Then FileDelete("C:\log.txt") FileDelete("C:\test.txt") MsgBox(0, "System", "The history has been successfully deleted") ExitLoop EndIf WEnd DllClose($dll) thank you for help u already did to me, i really appreciate it Link to comment Share on other sites More sharing options...
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