Skip to content

Instantly share code, notes, and snippets.

@takurx
Last active January 22, 2019 07:20
Show Gist options
  • Save takurx/3fed4ede3e4db5e8c6f3be31248624ae to your computer and use it in GitHub Desktop.
Save takurx/3fed4ede3e4db5e8c6f3be31248624ae to your computer and use it in GitHub Desktop.
"hello world" on user code of Ranorex
//In console "hello world" on user code of Ranorex
//ref.1 https://docs.microsoft.com/ja-jp/dotnet/csharp/programming-guide/inside-a-program/hello-world-your-first-program
//ref.2 https://www.wareko.jp/blog/post-20367
//ref.3 http://bignight.hatenablog.com/entry/2015/01/14/191931
//ref.4 https://stackoverflow.com/questions/15604014/no-console-output-when-using-allocconsole-and-target-architecture-x86
//ref.5 https://msdn.microsoft.com/ja-jp/library/system.io.textwriter(v=vs.110).aspx
//ref.6 https://www.ranorex.com/help/latest/lesson-7-code-modules
///////////////////////////////////////////////////////////////////////////////
//
// This file was automatically generated by RANOREX.
// Your custom recording code should go in this file.
// The designer will only add methods to this file, so your custom code won't be overwritten.
// http://www.ranorex.com
//
///////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;
// >>> add
using System.Runtime.InteropServices;
using System.IO;
// <<< add
using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;
namespace usercode_test
{
public partial class Recording1
{
/// <summary>
/// This method gets called right after the recording has been started.
/// It can be used to execute recording specific initialization code.
/// </summary>
private void Init()
{
// Your recording specific initialization code goes here.
}
// >>> add
public void test()
{
CreateConsole();
Console.WriteLine("Hello World!");
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
public static void CreateConsole()
{
AllocConsole();
// stdout's handle seems to always be equal to 7
IntPtr defaultStdout = new IntPtr(7);
IntPtr currentStdout = GetStdHandle(StdOutputHandle);
if (currentStdout != defaultStdout)
// reset stdout
SetStdHandle(StdOutputHandle, defaultStdout);
// reopen stdout
TextWriter writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true };
Console.SetOut(writer);
}
// P/Invoke required:
private const UInt32 StdOutputHandle = 0xFFFFFFF5;
[DllImport("kernel32.dll")]
private static extern IntPtr GetStdHandle(UInt32 nStdHandle);
[DllImport("kernel32.dll")]
private static extern void SetStdHandle(UInt32 nStdHandle, IntPtr handle);
[DllImport("kernel32")]
static extern bool AllocConsole();
// <<< add
}
}
//In messagebox "hello world" on user code of Ranorex
//ref.1 https://dobon.net/vb/dotnet/form/msgbox.html
//ref.2 https://msdn.microsoft.com/ja-jp/library/519bytz3(v=vs.110).aspx
///////////////////////////////////////////////////////////////////////////////
//
// This file was automatically generated by RANOREX.
// Your custom recording code should go in this file.
// The designer will only add methods to this file, so your custom code won't be overwritten.
// http://www.ranorex.com
//
///////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;
// >>> add
using System.Windows.Forms;
// <<< add
using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;
namespace usercode_test
{
public partial class Recording1
{
/// <summary>
/// This method gets called right after the recording has been started.
/// It can be used to execute recording specific initialization code.
/// </summary>
private void Init()
{
// Your recording specific initialization code goes here.
}
// >>> add
public void test()
{
//メッセージボックスを表示する
DialogResult result = MessageBox.Show("Hello, world.");
}
// <<< add
}
}
//In messagebox "hello world" and top of window on user code of Ranorex
//ref.1 https://dobon.net/vb/dotnet/form/msgbox.html
//ref.2 https://msdn.microsoft.com/ja-jp/library/519bytz3(v=vs.110).aspx
//ref.3 https://stackoverflow.com/questions/1220882/keep-messagebox-show-on-top-of-other-application-using-c-sharp
///////////////////////////////////////////////////////////////////////////////
//
// This file was automatically generated by RANOREX.
// Your custom recording code should go in this file.
// The designer will only add methods to this file, so your custom code won't be overwritten.
// http://www.ranorex.com
//
///////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;
// >>> add
using System.Windows.Forms;
// <<< add
using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;
namespace usercode_test
{
public partial class Recording1
{
/// <summary>
/// This method gets called right after the recording has been started.
/// It can be used to execute recording specific initialization code.
/// </summary>
private void Init()
{
// Your recording specific initialization code goes here.
}
// >>> add
public void test()
{
//メッセージボックスを表示する
DialogResult result = MessageBox.Show("Hello, world.", "Hello, world.", WinForms.MessageBoxButtons.OK, WinForms.MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
}
// <<< add
}
}
@takurx
Copy link
Author

takurx commented Apr 11, 2018

Please fit "namespace usercode_test", "public partial class Recording1" and name of function ( "public void test()" ) in your environment.

@takurx
Copy link
Author

takurx commented Jan 22, 2019

top_of_in_messagebox_hello.cs : It was added code that "warning hello, world window" is top of other windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment