Sign in to follow this  
Followers 0
Apocalypse

Using AutoItX to get handles in C++

9 posts in this topic

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?

Share this post


Link to post
Share on other sites



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


[center]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.[/center]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

In C++ the command AU3_WinGetHandle requires four arguments: Title, Text, RetText, Flag

I still don't see the problem, but thats not it.

Thanks anyway. :whistle:

Edited by Apocalypse

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

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