T8-Basic Event Handling, Mapping Modes
T8-Basic Event Handling, Mapping Modes
K. Vimala Devi
Sr. Lecturer
Dept. of CSE
AKCE – Kalasalingam University.
T8
Basic Event Handling, Mapping Modes,
and a Scrolling View
if (m_rectEllipse.PtInRect(point))
{ // point is inside rectangle}
CRect LPCRECT Operator
• Notice that CWnd::InvalidateRect takes an LPCRECT parameter
(a pointer to a RECT structure), not a CRect parameter.
CRect rectClient;
GetClientRect(rectClient);
CRgn rgn;
rgn.CreateEllipticRgnIndirect(m_rectEllipse);
if (rgn.PtInRegion(point))
{ // point is inside ellipse}
...
T8
Mapping Modes
•But you're allowed to change the origin through calls to the CDC functions
SetViewportOrg and SetWindowOrg.
•Here's some code that sets the window origin to (100, 100) in logical coordinate
space and then draws a 200-by-200-pixel square offset by (100, 100).
•The logical point (100, 100) maps to the device point (0, 0). A scrolling window
uses this kind of transformation.
•The only difference among the fixed mapping modes is the actual scale
factor, listed in the table shown here.
With these mapping modes, your drawing can change size as the
user changes the size of the window.
Also, if you invert the scale of one axis, you can "flip" an image
about the other axis and you can define your own arbitrary fixed-
scale factors.
It generates the correct function prototype in the class's header file and a
skeleton function in the CPP file.
Select the class name CEx04aView in the Object IDs list, and then double-click
on the OnPrepareDC function in the Messages list. Edit the function as shown
here:
The Microsoft Windows device context is the key GDI element that represents a
physical device. Each C++ device context object has an associated Windows device
context, identified by a 32-bit handle of type HDC.
• The base class CDC has all the member functions (including some virtual functions)
that you'll need for drawing.
• If you (or the application framework) construct an object of a derived device context
class, you can pass a CDC pointer to a function such as OnDraw.
• For the display, the usual derived classes are CClientDC and CWindowDC. For other
devices, such as printers or memory buffers, you construct objects of the base class
CDC.
• It is easy to write code that works with both the printer and the display. A statement in
OnDraw such as
pDC->TextOut(0, 0, "Hello");
– sends text to the display, the printer, or the Print Preview window, depending on
the class of the object referenced by the CView::OnDraw function's pDC
parameter.
Constructing and Destroying CDC Objects
• The default OnPaint calls OnDraw with a properly set up device context,
but sometimes you'll need display-specific drawing code.
• Once you have a CDC pointer, however, you can use it as you would
any other device context pointer.
void CMyView::OnPaint()
{
CPaintDC dc(this);
OnPrepareDC(&dc);
dc.TextOut(0, 0, "for the display, not the printer");
OnDraw(&dc); // stuff that's common to display and printer
}
GDI Objects
Here's a list of the GDI derived classes:
• CBrush—A brush defines a bitmapped pattern of pixels that is used to fill areas
with color.
• CPen—A pen is a tool for drawing lines and shape borders. You can specify a
pen's color and thickness and whether it draws solid, dotted, or dashed lines.