I want to add an image to the window's title bar. I know that is not possible with native Winforms tools but it should be able with the WinApi calls.
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr GetWindowDC(IntPtr hwnd);
[DllImport("user32.dll", SetLastError = true)]
private static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc);
protected override void WndProc(ref Message m)
{
IntPtr result = IntPtr.Zero;
bool callDWP = !Win32Interop.DwmDefWindowProc(m.HWnd, m.Msg, m.WParam, m.LParam, out result);
switch (m.Msg)
{
case Win32Messages.WM_NCPAINT:
IntPtr hdc = GetWindowDC(m.HWnd);
if ((int)hdc != 0)
{
Graphics g = Graphics.FromHdc(hdc);
g.DrawImage(Resources.Logo, new Point(0, 0));
ReleaseDC(m.HWnd, hdc);
}
break;
}
m.Result = result;
if (callDWP)
{
base.WndProc(ref m);
}
}
The image is not rendered. What am I doing wrong?