• 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

    • I’ve just paid £290/$390 for a 4TB Samsung 990 Pro for my PS5 Pro so it’s not too far from the going rate. Microsoft should definitely copy Sony and let users buy their own SSD in their next consoles rather than this proprietary stuff. I paid £374/$505 for the 2TB Seagate card for my Series X a few years ago so it’s not exactly over priced. 4TB of NVMe storage ain’t cheap!
    • The EU regulations force companies to respect users privacy, choice and data. Something all tech companies have abused to the hilt and would continue to do so if it wasn’t for important legislation and laws the EU brought in, which have been adopted elsewhere around the world. The EU can be a nuisance, but they actually do more good than harm. Forcing Apple, Google, Microsoft etc to make changes hasn’t negatively impacted anyone apart from their financials as they aren’t free to pillage our data like they once were, unless they explicitly provide options to obtain consent.
    • Windows 10 Enterprise IoT LTSC will continue getting updates until January 2032. I would expect support from most programs to continue until then. Firefox still supports Windows 7 (until the end of August), which will be just over 16 years since release. Windows 10 will be of a very similar age in January 2032. I'm sure some things like games will move on earlier, but I imagine a Windows 10 machine will be safe and usable for a long time to come yet, despite the pressure and fearmongering from those who stand to gain from selling you a new PC.
    • Refined dock and bug fixes land in latest Elementary OS 8 updates by David Uzondu If you're running Elementary OS 8, there's a new round of updates available, bringing some neat enhancements, particularly to its signature Dock and the underlying window manager, Gala. If you are not familiar, Elementary OS positions itself as a polished alternative to Windows and macOS. It runs its own custom desktop environment called Pantheon, with Gala handling all the window management magic, like animations and how windows behave. In the new update, the Dock gets some notable new tricks, including the return of a couple of features that old-school Plank (the Dock's foundation) users might remember. For starters, the Dock now shows multiple indicator dots beneath an app icon if you have more than one window open for that application, which is useful for quickly seeing what is running. Plus, if you are dragging something and hover over an app icon in the Dock, it will cycle through that app's open windows, making it easier to drop your item into the right place. You can also now long-press an app icon to bring up its context menu, a nice touch for those who prefer that interaction. The elementary OS team also squashed some bugs related to hide modes and memory usage, keeping things running smoothly. Gala itself recently got a massive update, addressing around 20 reported issues and introducing a brand new Gesture Controller. This means users can now swipe up in the Multitasking View to close windows, a slick and intuitive gesture. App titles are now always shown in Multitasking View, a significant improvement for touchscreen users. Users also get notified when they take a screenshot with a keyboard shortcut, and this notification lets them jump straight to the image in Files. Some other welcome Gala improvements include saving window states on sleep and shutdown, and fixing an annoying bug where menus might only show once. For gamers, a fix for Lutris Flatpak installations causing Gala to crash with GE Proton setups will be a relief, and users of the Postman app will be happy to know that window captures for it are no longer partially rendered. Shifting back to Elementary OS 8, in System Settings, choosing light or dark mode properly snoozes your schedule instead of outright disabling it. The Reduce Motion setting has been expanded to cover a wider array of animations, which is a blessing for folks prone to motion sickness. Hotcorners got some fixes too, and there is a new option to keep them active even when an application is full screen. Other notable updates include added screen reader support for notifications and the shortcut overlay, fixes for Flatpak sandbox issues that affected apps like Steam, and the latest version of GNOME Web, which brought better performance and a redesigned bookmarks sidebar. You can download all these updates by opening System Settings, heading to System, and hitting "Update All."
    • WSCC - Windows System Control Center 10.0.0.8 by Razvan Serea Windows System Control Center is a free, portable program that allows you to install, update, execute and organize the utilities from various system utility suites. WSCC can install and update the supported utilities automatically. Alternatively, WSCC can use the http protocol to download and run the programs. WSCC is portable, installation is not required. Extract the content of the downloaded zip archive to any directory on your computer. Free for personal use. The setup packages and updates are downloaded directly from their author's website! This edition of WSCC supports the following utility suites: Windows Sysinternals Suite (including support for "Sysinternals Live" service) NirSoft Utilities Mitec and more... WSCC - Windows System Control Center 10.0.0.8 changelog: Update Manager: scheduled updates will run even if WSCC is already running minor user interface improvements Download: WSCC (64-bit) | 6.9 MB (Free for personal use) Download: WSCC (32-bit) | 6.2 MB View: WSCC Homepage | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Enthusiast
      Epaminombas went up a rank
      Enthusiast
    • Posting Machine
      Fiza Ali earned a badge
      Posting Machine
    • One Year In
      WaynesWorld earned a badge
      One Year In
    • First Post
      chriskinney317 earned a badge
      First Post
    • Week One Done
      Nullun earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      186
    2. 2
      snowy owl
      131
    3. 3
      ATLien_0
      129
    4. 4
      Xenon
      121
    5. 5
      +Edouard
      91
  • Tell a friend

    Love Neowin? Tell a friend!