Apocalypse Posted February 21, 2007 Share Posted February 21, 2007 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 More sharing options...
Administrators Jon Posted February 21, 2007 Administrators Share Posted February 21, 2007 It returns the handle in szRetText. I really need to add some native versions of those calls to return pure HWNDs to make it easier. Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 21, 2007 Moderators Share Posted February 21, 2007 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 More sharing options...
Apocalypse Posted February 21, 2007 Author Share Posted February 21, 2007 (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. Edited February 21, 2007 by Apocalypse Link to comment Share on other sites More sharing options...
Administrators Jon Posted February 21, 2007 Administrators Share Posted February 21, 2007 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. Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
Apocalypse Posted February 23, 2007 Author Share Posted February 23, 2007 (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 February 23, 2007 by Apocalypse Link to comment Share on other sites More sharing options...
Administrators Jon Posted February 23, 2007 Administrators Share Posted February 23, 2007 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. Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
InfiniteNothing Posted December 5, 2008 Share Posted December 5, 2008 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 More sharing options...
Administrators Jon Posted December 6, 2008 Administrators Share Posted December 6, 2008 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. Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
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