Visual C++ and MFC Fundamentals Chapter 8 GDI Orientation and Transformations
reserved colors as default. A logical palette is a palette that an application creates for a
specific device context.
7.2 Drawing With Colors...................................................................................
7.2.1 Coloring a Pixel....................................................................................
As mentioned above, a pixel is the real object that holds a color. Although it is so small,
you can access a pixel and change its color. The pixels are stored in an array of [x][y]
value. In fact, when you try accessing a pixel, you would be asked to provide a color for
it. To change the color of a pixel, you can call the CDC::SetPixel() method. Its syntaxes
are:
COLORREF SetPixel(int x, int y, COLORREF crColor);
COLORREF SetPixel(POINT point, COLORREF crColor);
The pixel you want to access is defined by its x and y coordinates, which can also be
specified with a POINT or CPoint object as the point argument. The color you want to
specify is the crColor argument.
7.2.2 Rectangles With 3-D Effect...............................................................
Using colors, you can draw a rectangle with a 3-D effect. To do this, the CDC class
provides the Draw3dRect() method. Its syntaxes are:
void Draw3dRect(LPCRECT lpRect,
COLORREF clrTopLeft, COLORREF clrBottomRight);
void Draw3dRect(int x, int y, int cx, int cy,
COLORREF clrTopLeft, COLORREF clrBottomRight);
The rectangle to draw can be provided by its location and size through the x, y, cx, and cy
arguments. You can also pass it as a pointer to RECT or CRect for the lpRect argument.
Specify a color for the top and left sides of the rectangle as the clrTopLeft argument. The
clrBottomRight argument holds the color of the right and bottom sides of the rectangle.
Here is an example:
void CExoView::OnDraw(CDC* pDC)
{
pDC->Draw3dRect(20, 24, 238, 108, RGB(192, 192, 192), RGB(128, 128, 128));
}