Click to See Complete Forum and Search --> : Controlling An External Application?
bsgoins
September 14th, 2007, 03:47 PM
I'm trying to be able to control an external application from the one I'm writing. I can get the window handle of the other app successfully. I tried to enumerate the properties of the other window using EnumProp and PropEnumProc. I guess it successfully enumerates the properties (it prints "hello" for as many properties as it encounters), but I can't do anything with the parameters that go through my Callback function. I tried dereferencing and printing the LPCTSTR that comes through, and it gives an error and shuts down my program, and I have no idea what to do with the data handle (HANDLE object) that comes through. So I'm stuck.
Am I on the right track to being able to programmatically control another application? How can I see or otherwise use the parameters that are coming through my callback function?
kirants
September 14th, 2007, 03:57 PM
What does your PropEnumProc look like ? Please post code.
What are the property names that you are getting ? Instead of printing "hello", it would be useful if you print out lpszString in PropEnumProc.
Last and actually most important. controlling an external application is a very broad term and can mean myriad things. What specifically are you trying to control ?
bsgoins
September 14th, 2007, 04:09 PM
I have a simple callback right now, just to see what's in the window. Once it gets here, it gives me an error saying my program needs to close, so I can't get any names. I tried it with and without the dereference operator.
BOOL CALLBACK PropEnumProc(HWND hwnd, LPCTSTR lpszString, HANDLE hData) {
cout << *lpszString << endl;
return TRUE;
}
And I'm trying to control Sony Ericsson's Wireless Manager.
kirants
September 14th, 2007, 04:32 PM
Per MSDN documentation for SetProp
lpString
[in] Pointer to a null-terminated string or contains an atom that identifies a string. If this parameter is an atom, it must be a global atom created by a previous call to the GlobalAddAtom function. The atom must be placed in the low-order word of lpString; the high-order word must be zero.
So, your code should actually be something like this:
BOOL CALLBACK PropEnumProc( HWND hwnd,
LPCTSTR lpszString,
HANDLE hData
)
{
if(0 == HIWORD(lpszString))
{
TCHAR szAtomName[10];
GetAtomName(LOWORD(lpszString),szAtomName,sizeof(szAtomName)/sizeof(TCHAR));
cout << szAtomName << endl;
}
else
{
cout << lpszString << endl;
}
return TRUE;
}
And I'm trying to control Sony Ericsson's Wireless Manager.
That still doesn't make it any clearer ;) What aspect of the Wireless Manager are you trying to control ?
bsgoins
September 14th, 2007, 04:40 PM
Ok. Thank you. I had read that excerpt, but it didn't make any sense to me until I saw the code you wrote.
By control, I mean things like pressing the buttons in the application window, reading items off of the menu bar at the top, etc. Does that make it any clearer?
kirants
September 14th, 2007, 04:46 PM
In that case, EnumProps isn't really going to be of much help, I guess. EnumProps relies heavily on whether the application that created the window has set those properties. Do you know if the wireless manager application is doing that ? If not, you are out of luck using that approach.
each of those activities you said has to be tackled in a different way. So, it is difficult to generalize how to go about.
BTW, just curious. What do you finally want to achieve ? Are you attempting at some kind of automated testing of this application ?
bsgoins
September 14th, 2007, 05:09 PM
Yeah, I guess you could say that's what I'm trying to do. Thanks for the advice. I wasn't really sure.
Any advice on how to approach the task?
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.