Sign in to follow this  
Followers 0
E1M1

What's the C++ code for WinWaitNotActive()?

13 posts in this topic

What's the C++ code for WinWaitNotActive()?

Is there any specific function that is called or does autoit just get title of active window like 50 times in sec and return when current window title is not equal to old window title?


edited

Share this post


Link to post
Share on other sites



It's basically a loop with a sleep in it. It just checks and returns when it happens or times out.

Share this post


Link to post
Share on other sites

I wonder what's good sleep for it? 10?


edited

Share this post


Link to post
Share on other sites

I wonder what's good sleep for it? 10?

It depends on the demands of your application. If it's some unattended script, then it might as well check every 30 seconds. By default, it probably uses WinWaitDelay option: 250ms.

Share this post


Link to post
Share on other sites

I managed to code this but for some reason I see only 1 char.

#include <string>
#include <windows.h>
#include <stdio.h>
#include <iostream.h>

using namespace std;

int main()
{
    HWND handle = GetForegroundWindow();
    int len = GetWindowTextLengthW( handle )+1;
    wchar_t * title = new wchar_t[len];
    GetWindowTextW(handle, title, len );
    wprintf("%s",title) ;
    return 0;
}

edited

Share this post


Link to post
Share on other sites

It only returns one character of any active window?

Share this post


Link to post
Share on other sites

It was printf's problem. Got whole title with msgbox..

But I found ineresting thing.. Compare C++ time to autoit time. AutoIt is about 21 times slower.

#include <string>
#include <windows.h>
#include <stdio.h>
#include <iostream>

using namespace std;

wstring GetActiveWindowTitle()
{
    wstring title;
    HWND handle = GetForegroundWindow();
    int len = GetWindowTextLengthW( handle )+1;
    wchar_t * omgtitle = new wchar_t[len];
    GetWindowTextW(handle,omgtitle,len);
    title += omgtitle;
    return title;
}

int main()
{
    int i = 1;
    for (i;i < 200000;i++)
    {
        GetActiveWindowTitle();
    }
    //wstring loltitle;
    //loltitle = L"Title is: ";
    //loltitle += GetActiveWindowTitle();
    //MessageBoxW(NULL,loltitle.c_str(),L"hi",0);
    return 0;
}

$in = TimerInit()
for $i = 1 to 200000
    WinGetTitle("[Active]")
Next
ConsoleWrite(TimerDiff($in)&@CRLF)

edited

Share this post


Link to post
Share on other sites

I wonder if that has anything to do with the fact that AutoIt is an interpreted language?

Posted Image

True. I didn't think interpreting takes that much time.

consolewrite C++ and autoit are almost equal.. C++ is like 1.2 times faster, not 21.


edited

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

~

Edited by Mobius

Share this post


Link to post
Share on other sites

Right Mobius. I didn't say anything bad about autoit speed. I just mentioned difference between 2 languages and that's all.


edited

Share this post


Link to post
Share on other sites

It was printf's problem. Got whole title with msgbox..

But I found ineresting thing.. Compare C++ time to autoit time. AutoIt is about 21 times slower.

AutoIt goes to sleep to conserve CPU when it's waiting, and then it also adds on the WinWaitDelay when it detects a window so that it gets a chance to be fully active before you start sending keys to it. So be default a wait is always going to be around the 300ms mark.

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  
Followers 0