• 0

[C#] Reading/Writing textbox on other program


Question

Good Morning All -

I consider myself an Intermediate Level programmer. I do web design in my current position, but I also have experience with other languages. I am currently working on my 4 year degree in Computer Science. I understand different topics and terms, but this is confusing me.

The Problem: We have a help desk ticket system called ARS Remedy 4. When a ticket is being filled out we have a list of questions that are different for each problem. We need to answer these questions that show up in a textfield. We are still a ways off of implementing Remedy 7 (which contains Magic [the program that does what I am trying to create]).

I am trying to find a find a way to interact with Remedy. I want to pull the text from the textbox and then parse it and popup a window asking the questions in a much easier to read and fill out form. Then once we are done filling it out I want to have it put the information back into Remedy.

I have looked into the Windows API and I can use Interop (is that the right term?) in C#, but I am still a little lost as to which API functions to use. I looked into FindWindow, but I need to see if I can find the actual component in the application, and I don't know where to find this. I have tried to find managed code in C# that can get me the components, but what I did find wouldn't return an instantiated object (it may not really exist or access denied?). I am sure that there may be something out there on Google, but all my searches have not yielded the right results. My hunch is that I am not searching correctly.

Some may say that there might be an API for Remedy that I can use. I cannot find one, or I don't have access to BMC's site to find more information. Besides, Remedy 4 is old and not really supported anymore.

Thank you for any help that you can provide!

2 answers to this question

Recommended Posts

  • 0

In Windows, every object on a form is classed as a window, and as such, can send and receive messages.

You could probably achieve the above using a process similar to this pseudo-code:

var windowHandle = FindWindow("WindowClass", "Window Caption")
var textboxHandle = FindWindowEx(windowHandle, 0, "TextBoxClass", null)

string message = "Hello World!"
byte[] buffer = ToBytes(message)
SendMessage(textBoxHandle, WM_SETTEXT, 0, buffer)

So, if I was going to accomplish this in .NET:

public class ExternalWriter 
{
	[DllImport("user32.dll", SetLastError = true)]
	private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

	[DllImport("user32.dll", SetLastError = true)]
	private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string className, string lpszWindow);

	[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
	private static extern int SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, string lParam);

	private const int WM_SETTEXT = 12;

	public void DoExternalWrite(string text) 
	{
		IntPtr parent = FindWindow("<window class name>", "<window title">);
		IntPtr child = GetchildHandle(parent, "<class name>");

		SendMessage(child, WM_SETTEXT, IntPtr.Zero, text);
	}

	private IntPtr GetChildHandle(IntPtr parent, string className) 
	{
		/* Here you need to perform some sort of function to obtain the child window handle, perhaps recursively
		 */

		IntPtr child = FindWindowEx(parent, IntPtr.Zero, className, null);
		child = FindWnidowEx(parent, child, className, null);

		/* You can use a tool like Spy++ to discover the hierachy on the Remedy 7 form, to find how many levels you need to search
		 * to get to the textbox you want */

		return child;
	}
}

I haven't tested this so you will probably have to put something together that is similar, make sure you use Spy++ on the BMC Remedy window to find the window class of the textbox control. You'll notice in my .NET implementation I haven't bothered converting the string to a byte array, because the user32.dll function is overloaded to provide a string lParam version. You could of course use Convert.ToByteArray(<string>) to do that for you.

Hope that helps, happy Coding!

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • It's a 3v3 fighting system which Mortal Kombat has never done, unless you are talking about the hitstop animation and so on
    • Apple's future is glass-centric, and the new glassy UI is just the beginning  by Hamid Ganji Apple will unveil its overhauled UI experience at today’s WWDC event. The new UI will be available on all Apple devices, including iPhones, iPads, and Mac devices, and it will take most of its cues from visionOS. Bloomberg’s Mark Gurman has now provided us with new details about Apple’s new UI. The new interface is called Liquid Glass and has “sheen and see-through visuals of a glassy surface.” The name represents Apple’s approach to designing the new interface. The new UI also brings “transparency and shine effects in all of Apple’s tool bars, in-app interfaces and controls.” However, Gurman notes that the Liquid Glass interface will lay the groundwork for Apple’s future products, especially the 20th anniversary iPhone. It was already reported that Apple plans to unveil at least two new devices in 2027, which coincides with the iPhone’s 20th anniversary. The first model would be the long-awaited foldable iPhone. However, the second model, the 20th anniversary iPhone, is a glass-centric model that aligns with Apple’s new UI concept. According to Gurman, the 20th anniversary iPhone has curved glass sides and edges. It also features “extraordinarily slim bezels” and “no cutout section in the screen.” The phone is reportedly called “Glasswing,” which refers to the type of butterfly with transparent wings. Apple’s upcoming iOS 26 is the biggest overhaul to iPhone UI since the launch of iOS 7 in 2013. The new UI also hits iPadOS 26, tvOS 26, visionOS 26, watchOS 26, macOS 26. As a side note, the new “26” on the name of Apple’s operating system represents the year 2026.
    • Listen, adrynalyne - You're trolling me (I've known this for months). If you have something meaningful to say - say it, don't ask as if you know something, becauser you know sh*t. Ok?
  • Recent Achievements

    • Week One Done
      Al_ earned a badge
      Week One Done
    • Week One Done
      MadMung0 earned a badge
      Week One Done
    • Reacting Well
      BlakeBringer earned a badge
      Reacting Well
    • Reacting Well
      Lazy_Placeholder earned a badge
      Reacting Well
    • Dedicated
      Epaminombas earned a badge
      Dedicated
  • Popular Contributors

    1. 1
      +primortal
      475
    2. 2
      +FloatingFatMan
      273
    3. 3
      ATLien_0
      242
    4. 4
      snowy owl
      211
    5. 5
      Edouard
      182
  • Tell a friend

    Love Neowin? Tell a friend!