Jump to content

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


E1M1
 Share

Recommended Posts

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

Link to comment
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

Link to comment
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

Link to comment
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

Link to comment
Share on other sites

  • Administrators

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