【正文】
millimeter. ? MM_TWIPS Each logical unit is converted to 1/20 of a point. (Because a point is 1/72 inch, a twip is 1/1440 inch.) Chapter 4 Basic Event Handling, Mapping Modes and a Scrolling View VC++ Programming @ UESTC 31 ? MM_TEXT Each logical unit is converted to 1 device pixel. Positive x is to the right。 positive y is down. ? You’re required to work between logical and device systems. ? Windows GDI takes care of the logicaltodevice translation. – Using CDC:LPtoDP() and DPtoLP() Chapter 4 Basic Event Handling, Mapping Modes and a Scrolling View VC++ Programming @ UESTC 32 ? Let’s kook at the ex04c project to understand more about it. void CEx04cView::OnLButtonDown(UINT nFlags, CPoint point) { CClientDC dc(this)。 OnPrepareDC(amp。dc)。 CRect rectDevice = m_rectEllipse。 (rectDevice)。 //Rect is now in device corordinates if ((point)) { if (m_nColor == GRAY_BRUSH) m_nColor = WHITE_BRUSH。 else m_nColor = GRAY_BRUSH。 InvalidateRect(rectDevice)。 } } Chapter 4 Basic Event Handling, Mapping Modes and a Scrolling View VC++ Programming @ UESTC 33 ? CScrollView is derived from Cview and supports scrolling from the scroll bar. But we need to add codes to support keyboard scrolling. ? A window is larger than a viewport so we need to scrolling bar to traverse the whole window. Chapter 4 Basic Event Handling, Mapping Modes and a Scrolling View VC++ Programming @ UESTC 34 ? Again, let’s kook at the ex04c project class CEx04cView : public CScrollView IMPLEMENT_DYNCREATE(CEx04cView, CScrollView) BEGIN_MESSAGE_MAP(CEx04cView, CScrollView) //{{AFX_MSG_MAP(CEx04cView) ON_WM_KEYDOWN() ON_WM_LBUTTONDOWN() //}}AFX_MSG_MAP // Standard printing mands ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW,CScrollView::OnFilePrintPreview) END_MESSAGE_MAP() Chapter 4 Basic Event Handling, Mapping Modes and a Scrolling View VC++ Programming @ UESTC 35 ? void CEx04cView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { switch (nChar) { case VK_UP: OnVScroll(SB_LINEUP, 0, NULL)。 break。 case VK_DOWN: OnVScroll(SB_LINEDOWN, 0, NULL)。 break。 …………………………………….. default: break。 } } Chapter 4 Basic Event Handling, Mapping Modes and a Scrolling View VC++ Programming @ UESTC 36 ? Other Windows Messages WM_CREATE WM_CLOSE WM_WUERYENDSESSION WM_DESTROY window and its children active WM_NCDESTROY all children destroyed Chapter 4 Basic Event Handling, Mapping Modes and a Scrolling View