I am using the following code to draw on a single monitor:
Point cursorLocation;
NativeMethods.GetCursorPos(out cursorLocation);
Screen screen = Screen.FromPoint(cursorLocation);
Point h1 = new Point(screen.Bounds.Left, cursorLocation.Y);
Point h2 = new Point(screen.Bounds.Right, cursorLocation.Y);
Point v1 = new Point(cursorLocation.X, screen.Bounds.Top);
Point v2 = new Point(cursorLocation.X, screen.Bounds.Bottom);
using (Graphics graphics = Graphics.FromHwnd(NativeMethods.GetDesktopWindow())) {
NativeMethods.SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
graphics.DrawLine(Pens.Red, h1, h2);
graphics.DrawLine(Pens.Red, v1, v2);
}
Natively, this should theoretically draw on either monitor. However, it only draws on the primary. So, to fix this I am getting the DC of all the displays and trying to do it this way.
IntPtr hdc = NativeMethods.CreateDC("DISPLAY", IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
Graphics graphics = Graphics.FromHdc(hdc);
graphics.DrawLine(Pens.Red, h1, h2);
graphics.DrawLine(Pens.Red, v1, v2);
graphics.Dispose();
NativeMethods.ReleaseDC(IntPtr.Zero, hdc);
Go figure, this doesn't even draw to the screen at all. I have tried various overloads for CreateDC, as well as searched SO and other resources and I'm stumped.
Once this is resolved, anyone know how to get rid of flicker by refreshing the desktop using SHCHangeNotify? I'm only drawing two lines and it flickers like mad..)