DLXS Posted April 5, 2014 Posted April 5, 2014 Hi, I thought my script was a bit slow due to getpixel functions I was using but after checking properly I've realized that the bottle neck is actually in the winactivate function. It takes about 250ms to switch from one active window to another. Is it possible to speed up things? Aim of the script: I have several windows, one on top of each other. I want to get pixels from each of them so I have to activate them one by one. Getpixel or _ScreenCapture_CaptureWnd is pretty fast, but windowsactivate is a huge overhead. Is there any possible solution?
GordonFreeman Posted April 5, 2014 Posted April 5, 2014 (edited) Test and see if do not give problem in your function #include <WinAPI.au3> $sWinName = "WinActivate very slow - Any way to improve it? - General Help and Support - AutoIt Forums - Google Chrome" While 1 $hTimer = TimerInit() _WinAPI_ShowWindow ( WinGetHandle($sWinName), @SW_MINIMIZE) Sleep(20) _WinAPI_ShowWindow ( WinGetHandle($sWinName), @SW_RESTORE) $iDif = TimerDiff($hTimer) ConsoleWrite("|" & $iDif & "|" & @CRLF) WEnd Edited April 5, 2014 by GordonFreeman Frabjous Installation
DLXS Posted April 5, 2014 Author Posted April 5, 2014 (edited) Solution 1 if I can make it work (propose more if possible!!) I'm taking a look at winapi_showwindow (will it be faster?) but for some reason can't make it work: Code with winactivate working: WinActivate($ventanas[$i][0]) $handle = WinGetHandle($ventanas[$i][0]) *$Ventanas[$i][0] contains the title of the window. And with _WinAPI_ShowWindow I can't make it work: $handle = WinGetHandle($ventanas[$i][0]) _WinAPI_ShowWindow($handle) Shouldn't it work? Thanks, really appreciate an answer here EDIT: Going to try what you said, was actually checking this... Let's see if I can make it work. I update here. Edited April 5, 2014 by DLXS
DLXS Posted April 5, 2014 Author Posted April 5, 2014 (edited) Thanks gordonfreeman!!!!!! That's weird. Your code works and if I try the same code with another windows, it works. But if instead of minimize/restore I do SW_SHOW (or similar ones), it doesn't work. I'm trying combinations but can't find why. For example: This code should show my folder in front of google chrome, but it doesn't: $sWinName = "C:\Users\DLXS\Desktop\Script propio\Screens" #include <WinAPI.au3> $hTimer = TimerInit() _WinAPI_ShowWindow ( WinGetHandle($sWinName), @SW_SHOW) Sleep(50) $iDif = TimerDiff($hTimer) ConsoleWrite("|" & $iDif & "|" & @CRLF) However, if Y do minimize/restore it will work. Any idea why "show" is not working properly? Tried some other combinations like shownormal etc but didn't work either. Thanks a lot for your help! PS: If I hide and then SHOW, it works. But I don't want to use HIDE if possible, is it compulsory? Also, for some reason, some windows close when I do it. PS: 5 miliseconds with this, will be enough for my application. However, still interested to know how to improve it Final code: _WinAPI_ShowWindow ( WinGetHandle($ventanas[$i][0]), @SW_HIDE) _WinAPI_ShowWindow ( WinGetHandle($ventanas[$i][0]), @SW_SHOW) PPS: This is how my windows looks: Edited April 5, 2014 by DLXS
JohnOne Posted April 5, 2014 Posted April 5, 2014 I think _WinAPI_ShowWindow is a bit weird personally, I had trouble with it in the past.Do a bit of testing, I think some flags only activate the window if it is minimized and some work in other ways.Try using @SW_RESTORE or @SW_SHOWNORMAL, or others. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
DLXS Posted April 5, 2014 Author Posted April 5, 2014 Seems the best way will be hide + show because if I try other params it doesn't work. Indeed, pretty weird, I think it needs some more specification /details explanation. But oh well, at least I could make it work. From 300msecs with winactivate to 5-10 msec, quite crazy the difference... Samy
Solution trancexx Posted April 5, 2014 Solution Posted April 5, 2014 Built-in function is allways faster. If in your case it isn't then you are doing something wrong. For example, search for WinWaitDelay option. After you familiarize yourself with Opt() function, you'll see that 250 ms you experience is deliberate lag (only almighty knows why). Set WinWaitDelay option to 0. ♡♡♡ . eMyvnE
DLXS Posted April 5, 2014 Author Posted April 5, 2014 You are right! I save 50ms if I set Opt("WinWaitDelay", 0) at the beginning. Example: Opt("WinWaitDelay", 0) WinActivate($windoww[$i][0]) $handle = WinGetHandle($windoww[$i][0]) Gosh, it's my first time with autoit and I have done and undone so many functions already (facepalm). Alright, then I use the native way of course. Hope the code may be useful for somebody else. I didn't know of that option, how am I supposed to learn it without asking you guys? BTW, pretty amazing forum. One more questions (which is the same one as here '?do=embed' frameborder='0' data-embedContent>> though I can't edit the post as my last statement is no longer true): Why a buil-in function is better than a direct call to the functions in a dll (supposedly, this call is the same as the built-in function but skipping some steps)?? Thanks a lot one more time. You are all being very helpful and fast, I'm very surprised. Which I know more to help back already
Zedna Posted April 6, 2014 Posted April 6, 2014 Maybe in this my example can be some useful information for you ... '?do=embed' frameborder='0' data-embedContent>> Resources UDF ResourcesEx UDF AutoIt Forum Search
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