• 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

    • how big is your HDD that only has 100gb left? I take it this the main drive.  Is this a pc or laptop? I ask because changing hdd in pcs are much easier. You sure a good clean/purge of data wouldn't clear up space - have you ran disk cleanup? Which is part of windows..  You can for sure move data to your external drive, install programs to it, etc - but using it to store updates?   
    • How to record screen as GIF in Windows 11 by Taras Buria The Snipping Tool app is already quite a capable program for screenshots and screen recordings. Still, there is always room for improvement, and many users agree that the app needs the ability to save screen recordings as GIFs. Microsoft heard those users, and recent updates introduced the long-requested feature, allowing you to record your screen as a GIF. Here is how to do it. Record screen as a GIF in Windows 11 Note: By the time of publishing this article, GIF support in Snipping Tool is only available to Windows Insiders. However, you can enable that feature on stable Windows 11 releases as well; here is how: Go to store.rg-adguard.net, select ProductID in the first drop-down, paste 9MZ95KL8MR0L into the search box, and select Fast in the last drop-down. Press the checkmark button. Find and download Microsoft.ScreenSketch_2022.2505.21.0_neutral_~_8wekyb3d8bbwe.msixbundle in the list of apps. The version number could be newer, just make sure you are downloading an msixbundle file. Note that the browser will warn you about downloading a potentially harmful file. Open the file and click Update. Download ViveTool from GitHub and unpack the files in a convenient and easy-to-find folder. Run Command Prompt as Administrator and navigate to the folder containing the ViveTool files with the CD command. For example, if you have placed ViveTool in C:\Vive, type CD C:\Vive. Type vivetool /enable /id:47081492 and press Enter. The steps above might seem a bit tedious, but that is the only way to get GIF support in Snipping Tool without enrolling your device in the Windows Insider program. We will update the article once the feature is publicly available, so there is no need to jump through all the hoops just to make it work. Tip: You can always roll back Snippint Tool to the latest version from the Microsoft Store by uninstalling it and downloading it again. Now, with GIF support enabled in Snipping Tool, here is how to save a screen recording as a GIF in Windows 11: Press Win + Shift + S, select screen recording mode and record whatever you want. After the recording is over, Snipping Tool will open your video so that you can view, trim, or save it. At this point, all you have to do is click the GIF button in the upper-right corner. On the next screen, select your GIF quality and click Export to save as a file or Copy to copy it to the clipboard. And that is how you save screen recordings as GIFs in Windows 11. Note that Snipping Tool can only save GIFs for up to 30 seconds. Anything beyond that will be cut off. You might think that Clipchamp, Windows 11's built-in video editor, is a good option when you want to save a screen recording as a GIF. However, it really sucks at that. The video duration is capped at just 15 seconds, which is even worse than the Snipping Tool, and the output resolution is hilariously low. The latter makes it impossible to distinguish any details, and all you get is a blurry, pixelated mess. No, Clipchamp is not a good option for that. If you want to create GIFs that are longer than 30 seconds, a good option is to go with apps like ShareX, which is extremely flexible and customizable (and also free, which makes it one of our favorite must-have apps for Windows 11). Alternatively, you can record a video using the Snipping Tool and then convert it to a GIF using web-based services like Ezgif, another great free utility. Keep in mind that the larger your video resolution and the longer its duration, the bigger the final GIF size. Depending on the settings, GIFs could reach hundreds of megabytes, so you have to set your expectations correctly (and so do the settings, too).
    • I'll give you an example of "the settings problem." As awful as the HP Smart app is, it's magnitudes more useful than Settings when I need to do some deep dive stuff on my HP Officejet.
    • I hate to defend Apple but this marketing and they are only "desperate" to move from #3 to #1 for biggest company in the world.
    • There's very granular stuff in the legacy Control Panel that will probably never be accessible from settings. But that stuff will still be there if you know where to look.
  • Recent Achievements

    • Week One Done
      DXB APPS earned a badge
      Week One Done
    • One Month Later
      DecaffKnight94 earned a badge
      One Month Later
    • Dedicated
      S.P earned a badge
      Dedicated
    • One Month Later
      adxnksd42031 earned a badge
      One Month Later
    • Rising Star
      aphanic went up a rank
      Rising Star
  • Popular Contributors

    1. 1
      +primortal
      661
    2. 2
      ATLien_0
      253
    3. 3
      Michael Scrip
      234
    4. 4
      Steven P.
      154
    5. 5
      +FloatingFatMan
      148
  • Tell a friend

    Love Neowin? Tell a friend!