This codes demonstrates what
is involved in writing a
dialog-based application for
Windows® using nothing but C
and the Windows API. It
further explores concepts
pertaining to the GDI, with
a focus on device contexts
and bit block transfers.
And, it shows how to
manipulate the clipboard.
There was a workaround
needed for the "Grab Color"
feature. The reason being is
that I used the
GetPixel
function for it; therefore,
if you have coordinates for
a non-client area in a
window, it returns
-1
.
This is not a valid color,
so I used
BitBlt
to rectify the problem by
copying the pixel to a
static control and then
using
GetPixel
on the control, thus
returning a valid color. The
following code demonstrates
this technique.
Collapse
Copy Code
hWndxy = WindowFromPoint(spoint);
hPreview = GetDlgItem(hWnd,IDC_STATIC_PREVIEW);
hDC = GetDC(hWndxy);
ScreenToClient(hWndxy, &cursor);
rgb = GetPixel(hDC, cursor.x, cursor.y);
if(rgb == -1)
{
HDC hDCPrev = GetDC(hPreview);
BitBlt(hDCPrev, 0, 0, 1, 1, hDC,
cursor.x, cursor.y, SRCCOPY);
rgb = GetPixel(hDCPrev, 0, 0);
ReleaseDC(hPreview, hDCPrev);
}
ReleaseDC(hWndxy, hDC);