Invoke a bug tracking application

My employer uses a home grown application for bug tracking that is written in Delphi. It works pretty well for their needs but it can be annoying at times when I know what bug report number I want to get to but I need to open the winforms application and search for that number.

I'm a huge fan of productivity tools so I wanted to make some tools that might help people with this annoyance.

I wanted to create a very basic application that I could build tools off of the basic concept. I created a C# application that does some pretty scary stuff to get to the bug tracking software. The bug tracking software only supports windows messaging of passing in a bug report number. This meant I had to know what process to send the message to, but once I know what process, it's easy to write some crap code to send the message and have that bug report open.

I am not an expert on windows messaging, in fact I am not even a fan. I had to use some DLLImports to be able to send the message

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

I also used a FindWindow method to find the bug tracking application. I require my users to already have the bug tracking application open and that is a fair requirement at my employer because we live by it.

public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

In my Main method I get the bug report number from the string arguments, find the window, and send the bug report number message to the window.

IntPtr MainWindow = FindWindow(null, settings.BugTrackingFormCaption);

if (bugReportNumber > 0 && MainWindow.ToInt32() > 0)
    SendMessage(MainWindow, WM_USER + 1, (IntPtr)bugReportNumber, IntPtr.Zero);

Like I said, I am no expert on windows messaging. I had to google a bit to get the SendMessage syntax. I just know I want to send bugReportNumber that I got from the command line arguments and send it to the window I got from MainWindow. You can see that I also created a settings file in case the form caption changes.

To avoid a flicker of a console window when the executable is invoked, I used a windows application output type but I never create a form or show it so I never see anything pop up other than the bug report.

So now if I run the application at the command line at pass in a bug report number it opens up a new window for the bug report I typed it. That's perfect! But not that useful... however, it is something I can really build on.

Even this executable alone, I can do some pretty cool things with it. I'm a huge Launchy fan. I can train Launchy to find the executable and press tab to pass in a bug report number!

I have more plans for using this executable in other tools so stay tuned.