I want to draw directly on the desktop ( As wallpaper or over all, I don't mind ) in C#, but I have not been able to find how. I found this:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
class Program {
[DllImport("User32.dll")]
static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("User32.dll")]
static extern void ReleaseDC(IntPtr dc);
static void Main(string[] args) {
IntPtr desktop = GetDC(IntPtr.Zero);
using (Graphics g = Graphics.FromHdc(desktop)) {
g.FillRectangle(Brushes.Red, 0, 0, 100, 100);
}
ReleaseDC(desktop);
}
}
It actually draws a red rectangle but within 1 second, Visual Studio gives me this error:
PInvokeStackImbalance was detected
Any help is appreciated, Thanks