G
Guest
I am having trouble getting the background color of a control in another app.
I use FindWindow() to get the handle of a button on a form. This works fine
because I can successfully send a mouse click to the button (via Sendmessage).
When trying to get the background color I am using the .NET Graphics class:
Color color = Color.Empty;
Graphics graphics = Graphics.FromHwnd(hWnd);
IntPtr hDC = graphics.GetHdc();
color = ColorTranslator.FromWin32(GetBkColor(hDC));
graphics.ReleaseHdc();
For some reason this always returns 'White" rather than the background color
of the control. I have also tried using straight GDI32 and USER32 calls:
IntPtr hDC = GetDC(this.HWnd);
int bkColor = GetBkColor(hDC);
ReleaseDC(this.HWnd, hDC);
color = ColorTranslator.FromWin32(bkColor);
and this also seems to return "White". Any help is appreciated.
Matt
I use FindWindow() to get the handle of a button on a form. This works fine
because I can successfully send a mouse click to the button (via Sendmessage).
When trying to get the background color I am using the .NET Graphics class:
Color color = Color.Empty;
Graphics graphics = Graphics.FromHwnd(hWnd);
IntPtr hDC = graphics.GetHdc();
color = ColorTranslator.FromWin32(GetBkColor(hDC));
graphics.ReleaseHdc();
For some reason this always returns 'White" rather than the background color
of the control. I have also tried using straight GDI32 and USER32 calls:
IntPtr hDC = GetDC(this.HWnd);
int bkColor = GetBkColor(hDC);
ReleaseDC(this.HWnd, hDC);
color = ColorTranslator.FromWin32(bkColor);
and this also seems to return "White". Any help is appreciated.
Matt