Overlays

by Patrick Sears on November 02, 2014 at 15:52

This was another fairly simple idea that turned into something larger than I'd intended. I've used simple Autohotkey scripts to draw any overlays I've needed in the past, but it was far from user-friendly. Needing to modify the script for every movement of the overlay, and running multiple instances just to draw more than one overlay got much too tedious.

I initially considered expanding the Autohotkey script to draw a collection of overlays, and use command line arguments for settings. After about fifteen minutes of that, however, I came to the conclusion a clean interface with a full GUI would be a much less painful experience.

Now there's a relatively clean interface built with WPF, support for saving and loading overlays, smoothly parenting overlays to a window to track its movement, and some customization for the overlays themselves.

The only disappointing piece was needing to use the SetWindowLong function from the user32.dll to allow for click-through on the overlays. The IsHitTestVisible property on WPF controls doesn't seem to work correctly with shapes drawn to a canvas, so I had to do it the old fashioned way.


SetWindowLong
(
    this.Handle,
    GWL.ExStyle,
    GetWindowLong(this.Handle, GWL.ExStyle) | (int)WS_EX.Transparent | (int)WS_EX.Layered
);

Everything else came together fairly nicely.