Jump to content

Using AutoItX to get handles in C++


Apocalypse
 Share

Recommended Posts

I was under the impression that I could do something along the following lines to get a window handle:

hdc = GetDC( AU3_WinGetHandle("Window Title", "", "", 0) );

The AutoItX help file says that the command WinGetHandle returns a string, but the Visual Studio claims that it returns a void and therefore cannot be used.

Can someone help me correct the above line of code?

Link to comment
Share on other sites

  • Moderators

I was under the impression that I could do something along the following lines to get a window handle:

hdc = GetDC( AU3_WinGetHandle("Window Title", "", "", 0) );

The AutoItX help file says that the command WinGetHandle returns a string, but the Visual Studio claims that it returns a void and therefore cannot be used.

Can someone help me correct the above line of code?

Looks like you're calling it with too many parameters to me.

hdc = GetDC(AU3_WinGetHandle("Window Title", ""));

But again, I've never used the DLL (Guess I should find a reason to lol).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Administrators

The function declaration:

AU3_API void WINAPI AU3_WinGetHandle(const char *szTitle, const char *szText, char *szRetText, int nBufSize);

Handle is returned as a string in szRetText (the only non-const)

char szHandle[256];
 AU3_WinGetHandle("title", "text", szHandle, 256)

Handle (as a string) is now in szHandle.

Link to comment
Share on other sites

I implemented the code below and continued on programming without testing since it had compiled (very stupid). Later on I traced my bugs back to this:

char szHandle[256];

AU3_WinGetHandle("title", "text", szHandle, 256)

hdc = GetDC( (HWND)szHandle );

I know that the first two lines are correct, but typecasting it to HWND does not produce favorable results when getting the device context.

I am sorry for asking for help with every line, but I rarely use C++ for work with other windows. That's why I incorperated AutoIt.

Edited by Apocalypse
Link to comment
Share on other sites

  • Administrators

szHandle is a STRING like "AAFCC0" - you can't just cast it to a HWND. You need to convert it to a pointer first that's why I said I need to add some native HWND methods too.

I suppose the next question would is going to be how, so:

int nNumber;

HexToDecimal( szHandle, nNumber );
HWND hWnd = (HWND)nNumber;



void HexToDecimal (char* HexNumber, int& Number)
{ 
    char *pStopString; 
    Number = strtol (HexNumber, &pStopString, 16);
}

This code is bad for a number of reasons but will probably work atm.

Link to comment
Share on other sites

  • 1 year later...

szHandle is a STRING like "AAFCC0" - you can't just cast it to a HWND. You need to convert it to a pointer first that's why I said I need to add some native HWND methods too.

I suppose the next question would is going to be how, so:

int nNumber;

HexToDecimal( szHandle, nNumber );
HWND hWnd = (HWND)nNumber;



void HexToDecimal (char* HexNumber, int& Number)
{ 
    char *pStopString; 
    Number = strtol (HexNumber, &pStopString, 16);
}

This code is bad for a number of reasons but will probably work atm.

How do I use HWND in a later call to, for example, WinExist. In the activeX API, WinExist seems to only want strings and not hWnd

For a bit of background information, I'm trying to detect a java popup window with no title and no text but a handle of 005807BA

Link to comment
Share on other sites

  • Administrators

Good point, I'll add a conversion function to the DLL to help.

I intend to add native HWND functions as well but I get stuck on the naming, e.g. WinExist to take string handles, plus WinExistEx to take HWNDs - but it quickly gets out of control.

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