I think I'm close: My return values are all good, but the window's background color isn't changing. I'm accessing a window created by .NET, (Not C or C++) so the window may be repainting itself through .NET functionality after the native GDI call.
Here's what I have:
using System.Runtime.InteropServices;
public class NativeWIN32
{
[DllImport("gdi32")]
public static extern int SetBkColor(IntPtr hDC, int crColor);
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
IntPtr hWnd = this.Handle;
Graphics windowGraphics = Graphics.FromHwnd(hWnd);
IntPtr hdc = windowGraphics.GetHdc();
int ret = NativeWIN32.SetBkColor(hdc, 0); // Set to black
}
}
Perhaps this will work for a Win32 window, otherwise I hope this helps someone else find the correct solution.