Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 8 GDI Orientation and Transformations Visual C++ and MFC Fundamentals


CExoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

pDC->SetTextColor(RGB(255, 25, 2));
pDC->TextOut(50, 42, "Johnny Carson", 13);

pDC->SetBkColor(RGB(0, 0, 128));
pDC->SetTextColor(RGB(128, 255, 255));
pDC->TextOut(50, 60, "The once king of late-night", 27);
}

If you want to know the background color applied on the object drawn, you can call the
CDC::GetBkColor() method. Its syntax is:

COLORREF GetBkColor() const;

This member function returns the color used to highlight the text, if the text is
highlighted. The highlighting of text is actually controlled by the CDC::SetBkMode()
method whose syntax is:

int SetBkMode(int nBkMode);

This method specifies whether the background color should be applied or not. This is set
by the nBkMode argument. It can have one of two values. If it is:

OPAQUE: the background would be drawn using the crColor value
TRANSPARENT: the background would not be drawn

If you want to find out what background mode is applied to the object(s) drawn, you can
call the CDC::GetBkMode() method. It is declared as follows:

int GetBkMode() const;

You can also draw text and include it in a (colored) rectangle. This can be done using the
CDC::ExtTextOut() method. Its syntax is:

virtual BOOL ExtTextOut(int x, int y, UINT nOptions, LPCRECT lpRect,
LPCTSTR lpszString, UINT nCount, LPINT lpDxWidths);


The x and y values specify the location of the first character of the text to be drawn.
The nOptions argument holds a constant that determines how the rectangle will be drawn.
It can be:
Free download pdf