Page 1 of 1

Custom Ranorex Classes

Posted: Tue Apr 27, 2010 10:54 pm
by this_is_ridiculous
Hi!
I'm new to Ranorex. I'm currently using version 2.1.4.xxxx. I've found there's no functionality to move and resize windows onboard. So i think it should be developed manually. And from this point i've got a few question:
1. Is there any way for cross converting e.g. Ranorex.Form to System.Windows.Forms.Form?

2. Is there any way to create custom Ranorex classes? Let's assume I need the funcionality mentioned above for tested application's windows (move and size) and I'd like them to be implemented as methods. So I need my custom class inherited from Ranorex.Form with some custom methods to do the work. If it is possible how could this be achieved?

3. If there is the way to create custom class inherited from the native Ranorex class will Ranorex Spy (the integrated one to the Studio) see my custom class instead of native class. This could be e.g. Window instead of Form with only a few methods added to it?

Thanks in advance.
Artem.

Re: Custom Ranorex Classes

Posted: Wed Apr 28, 2010 12:34 am
by Ciege
There was a brief discussion on resizing windows from Ranorex here that you might find useful.
http://www.ranorex.com/forum/resizing-a ... -t866.html

Re: Custom Ranorex Classes

Posted: Wed Apr 28, 2010 11:10 am
by this_is_ridiculous
That's not exactly what i need. We use Ranorex for product localization instead of testing. Product has flipping windows with side caption and it's not good to know where window does have its caption right now. And it really does not matter so much wheather it's dotNet window or MFC window to move or resize it using winapi if force the window to repaint itself. And Currently Move and size is functionality works throuh winapi. But window that should be moved or resized is passed as parameter to corresponding function. But I want these functions to be methods of any window that is detected by Ranorex as Form. That's the point.

Re: Custom Ranorex Classes

Posted: Wed Apr 28, 2010 11:36 am
by Support Team
Since V2.2 the Ranorex.Form class provides Move and Resize methods.

ad 1.) No, a Ranorex.Form just represents any kind of form - not necessarily a System.Windows.Forms.Form.

ad 2.) You can create your own adapter classe just by inheriting from Ranorex.Form. Your users can then use the custom adapter class.

ad 3.) Well, there is a way, but you have to create a Ranorex plugin and that ususally requires special training. Basically, you have to create a simple plugin (see this forum thread on how to create a simple Ranorex plugin) and then call the Ranorex.Core.ElementEngine.Register(string, type) method in the plugin initialization to register your custom adapter class (e.g. "FormCustom") for the "form" capability.

Regards,
Alex
Ranorex Support Team

Re: Custom Ranorex Classes

Posted: Wed Apr 28, 2010 12:29 pm
by this_is_ridiculous
Support Team wrote: 2.) You can create your own adapter classe just by inheriting from Ranorex.Form. Your users can then use the custom adapter class.

Regards,
Alex
Ranorex Support Team
Thanks! Nice to hear that.

Is there any kind of example of creating custom Ranorex classes and inheritance of Ranorex classes?

Would be greatful for any help.

Artem.

Re: Custom Ranorex Classes

Posted: Wed Apr 28, 2010 12:55 pm
by Support Team
Hi!

No sorry we don't have an example for creating his own adapter. But take a look to this link
http://support.microsoft.com/?scid=kb%3 ... 5&x=9&y=10

Regards,
Peter
Ranorex Support Team

Re: Custom Ranorex Classes

Posted: Wed Apr 28, 2010 1:09 pm
by this_is_ridiculous
That didn't help. I get this error:

Cannot implicitly convert type 'string' to 'Blackbox.Window'. An explicit conversion exists (are you missing a cast?) (CS0266)
my custom class description looks like:

Code: Select all


public class Window : Ranorex.Form
	{
		[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)]
    	private static extern void MoveWindow(IntPtr hwnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
		
    	public Window()
    	{
    		
    	}
    	
    	public void RePlaceReSize(int xPos, int yPos, int xSize, int ySize)
    	{
    		IntPtr winHandle = (IntPtr)this.Element.GetAttributeValue("Handle");
    		MoveWindow(winHandle, xPos, yPos, xSize, ySize, true);
    	}
    	
}

Next in the script i try to use Window instead of Form but i get error i mentioned above. What kind of cast am i missing?

Thanks in advance.
Artem.

Re: Custom Ranorex Classes

Posted: Wed Apr 28, 2010 4:37 pm
by this_is_ridiculous
Hi all!

Ok! For now i've resolved my problem with custom classes. May be someone also will face the same problem.

My aproach is the following:

Code: Select all

public class Window : Ranorex.Form
	{
		[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)]
    	private static extern void MoveWindow(IntPtr hwnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
    	    	
    	public Window()
    	{
    		
    	}
    	
    	public static Window NewWindow(string xPath)
    	{
    		Ranorex.Form frm = xPath;
    		return frm.As<Window>();
    	}
    	
    	    	
    	public void RePlaceReSize(int xPos, int yPos, int xSize, int ySize)
    	{
    		IntPtr winHandle = (IntPtr)this.Element.GetAttributeValue("Handle");
    		MoveWindow(winHandle, xPos, yPos, xSize, ySize, true);
    	}
    	
}
Don't worry about the DllImport. I used this WinApi to move and size windows before version 2.3. But still it does the trick. The RePlaceReSize could be used to prepare the window in one line of code for screenshooting for example. Actually this is the purpose of custom classes in Ranorex. Trying to move away from Borland SilkTest to more common coding aproach. :)

Than all windows/dialogs of the tested/localized app that are recorded as Ranorex.Form can be initialized like this:

Code: Select all

Window wConn = Window.NewWindow("/form[@title='_MAPCONNECT']");

Please see the screenshot attached.
You may ask why custom screenshooting method... It's because of layerd windows in the product. The opacity of those windows can be set up manually and these windows could be captured only using Windows framebuffer.

Regards!

Artem.

Re: Custom Ranorex Classes

Posted: Wed Apr 28, 2010 5:39 pm
by Support Team
To create a fully functional adapter, I recommend adding two implicit casts (from string and from Element) and an additional constructor to your adapter class. Please, see the attached file for a standard implementation of the MyAdapter class!
MyAdapter.cs
Regards,
Alex
Ranorex Support Team

Re: Custom Ranorex Classes

Posted: Wed Apr 28, 2010 5:48 pm
by this_is_ridiculous
WOW!!! Your support is awsome!! I wish all teams to have such a support! THANK YOU AGAIN!