Discussion:
Visual C++ examples for GUI automation
(too old to reply)
SQACSharp
2007-09-08 05:07:54 UTC
Permalink
Hi,

I'm looking for visual C++ (2005) examples for doing GUI automation.

Ex: Typing text to a notepad window, Clicking button in the windows
calculator and retrieving the result.

Any releated link will be usefull... I do this with VB using
enumwindow, SetWindowText, SetForeground window, SendMessage windows
API... but all the C++ examples found on the internet are not working
as expected.. ex:


#include <windows.h>
// Notepad must be started
int main()
{
HWND hWnd, hWndChild;
hWnd = FindWindow(NULL, L"Untitled - Notepad");
hWndChild = GetWindow(hWnd, GW_CHILD);
SendMessage((HWND) hWnd, WM_SETTEXT,0, (LPARAM)"New
Caption");
SendMessage((HWND) hWndChild, WM_SETTEXT,0,
(LPARAM)"New body text");
return 0;
}


This example change the caption and the text in the body for garbage
like "瑸" ([])

Any help?? Thanks!

Michel
Jeff☠Relf
2007-09-08 06:43:38 UTC
Permalink
You ( SQACSharp ) could add:
“ #define UNICODE ” before “ #include <windows.h> ”
and change “ "New body text" ” to: “ L"New body text" ”.

By the way, “ Automation ” is the running of external scripts,
e.g. what OLE and COM do.
SQACSharp
2007-09-08 07:44:45 UTC
Permalink
“ #define  UNICODE ” before “ #include <windows.h> ”
and change “ "New body text" ” to: “ L"New body text" ”.
By the way, “ Automation ” is the running of external scripts,
e.g. what OLE and COM do.
Thanks! Now the garbage characters are gone!

By automation I mean simulate user actions like ckiking button,
entering text to an edit field, Selecting item in a combobox, Getting
text or properties from a GUI controls... Most of the time it's done
using SendMessage/ Win32 API... Im doing a small GUI testing
tool...Anyway any links/examples releated in C++ will be ** really
appreciate **

Thanks again!
Michel
Jeff☠Relf
2007-09-08 22:29:36 UTC
Permalink
I'm migrating towards an all DirectDraw interface,
creating my own sytem for buttons and the like,
so I can't really help you with the GDI stuff, Mr. SQACSharp.

I cache glyphs, inserting them into a sorted, dynamic array.

By the way, I'm about to attempt an install of
“ Windows Vista Ultimate ”... whish me luck.

My video card has the minimum requirements
but not the recommended ones.
Ben Voigt [C++ MVP]
2007-09-10 18:02:39 UTC
Permalink
You could have avoided that problem by using the proper typesafe function,
SetWindowText. All it does is call SendMessage, but it does the nasty
casting for you, so you just pass in a string. The compiler would have
checked to make sure that you had the right type of character pointer.
" #define UNICODE " before " #include <windows.h> "
and change " "New body text" " to: " L"New body text" ".
By the way, " Automation " is the running of external scripts,
e.g. what OLE and COM do.
Thanks! Now the garbage characters are gone!

By automation I mean simulate user actions like ckiking button,
entering text to an edit field, Selecting item in a combobox, Getting
text or properties from a GUI controls... Most of the time it's done
using SendMessage/ Win32 API... Im doing a small GUI testing
tool...Anyway any links/examples releated in C++ will be ** really
appreciate **

Thanks again!
Michel
Igor Tandetnik
2007-09-10 18:12:15 UTC
Permalink
Post by Ben Voigt [C++ MVP]
You could have avoided that problem by using the proper typesafe
function, SetWindowText.
SetWindowText doesn't work across process boundaries. The documentation
clearly states as much.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
Ben Voigt [C++ MVP]
2007-09-10 19:31:03 UTC
Permalink
Post by Igor Tandetnik
Post by Ben Voigt [C++ MVP]
You could have avoided that problem by using the proper typesafe
function, SetWindowText.
SetWindowText doesn't work across process boundaries. The documentation
clearly states as much.
oops! You're right of course.

Still, best to make a wrapper to handle the casting.
Post by Igor Tandetnik
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
Brian Muth
2007-09-10 00:23:21 UTC
Permalink
Read up on Win32 Hooks with particular attention to WH_JOURNALRECORD and WH_JOURNALPLAYBACK types of hooks.


http://msdn2.microsoft.com/en-us/library/ms997537.aspx

http://www.codeproject.com/tools/winmacro.asp

Brian
Aurelien Regat-Barrel
2007-09-10 05:49:39 UTC
Permalink
Hello!

You should have a look at AutoIt/AutoItX:
http://www.autoitscript.com/autoit3/

Aurelien
Post by SQACSharp
Hi,
I'm looking for visual C++ (2005) examples for doing GUI automation.
Ex: Typing text to a notepad window, Clicking button in the windows
calculator and retrieving the result.
Any releated link will be usefull... I do this with VB using
enumwindow, SetWindowText, SetForeground window, SendMessage windows
API... but all the C++ examples found on the internet are not working
#include <windows.h>
// Notepad must be started
int main()
{
HWND hWnd, hWndChild;
hWnd = FindWindow(NULL, L"Untitled - Notepad");
hWndChild = GetWindow(hWnd, GW_CHILD);
SendMessage((HWND) hWnd, WM_SETTEXT,0, (LPARAM)"New
Caption");
SendMessage((HWND) hWndChild, WM_SETTEXT,0,
(LPARAM)"New body text");
return 0;
}
This example change the caption and the text in the body for garbage
like "瑸" ([])
Any help?? Thanks!
Michel
Loading...