Ranorex

English|Deutsch

Visual Studio Sample

print friendly page
This document describes how to use Ranorex in an existent Windows C++ application and how to automate a simple control in C++. All samples are located in the 'Samples' directory of your Ranorex installation path.

Create, build and run the sample

From the 'File' menu click 'New Project' and choose a Visual C++ Win32 Console Application Project.

In the 'AppWizard' dialog click 'Finish'.
Open the properties dialog of your project. ('Project' |
'Properties')


In the 'General' tab set the 'Output Directory' property to the path of the 'bin' folder of your Ranorex installation path.

Set the property 'Additional Include Directories' within the 'C/C++' | 'General' tab to the installation path of Ranorex ('include' folder)

Also set the linking directories at 'Additional Library Directories' to the installation path of Ranorex. ('lib' Folder)
Link the library RanorexCore.lib to your project by setting it under 'Linker' | 'Input' | 'Additional Dependencies'.
Open the file RanorexCppSample1.cpp
Include the header file RanorexCore.h
#include "RanorexCore.h" 
Insert the following code in the main function
printf("-------------------------------------\n");
printf(" Starting application calc.exe...    \n");
printf("-------------------------------------\n");
 
// Starting testapplication
int ret = RxApplicationStart(TESTED_APPLICATION);
if ( ret != 0 )
{
	printf(" ERROR: Cannot start application calc.exe\n");
	exit(1);
}
 
// Finding form by class name and activate it (timeout=3000 msec)
HWND form = RxFormFindClassName(TESTED_APPLICATION_CLASS, 1, TRUE, 3000);
if ( form == 0 )
{
	printf(" ERROR: Application not found\n");
	exit(2);
}
 
// Searching and clicking button 2
printf(" Searching and testing button 2\n");
HWND button2 = RxFormFindChildText(form, "2", MATCH_EXACT);
if ( button2 == 0 )
{
    printf(" ERROR: button2 not found\n");
    exit(3);
}
if ( RxMouseClickControl(button2) != 0 )
{
    printf(" ERROR: button2 click error\n");
    exit(4);
}
// Searching and clicking button 8
printf(" Searching and testing button 8\n");
HWND button8 = RxFormFindChildText(form, "8", MATCH_EXACT);
if ( button8 == 0 )
{
    printf(" ERROR: button8 not found\n");
    exit(5);
}
if ( RxMouseClickControl(button8) != 0 )
{
    printf(" ERROR: button8 click error\n");
    exit(6);
}
 
printf(" Closing application\n");
RxSleep(3000);
RxFormClose(form);
 
return 0;