In VC, accurately said in Windows programming, mapping mode is: mm_text, (device coordinate) mm_himetric, (logic coordinate) mm_isotropic, mm_anisotropic, ..... under development environment, (Windows default mode is MM_Text), we can change via setmapmode () When the mapping mode ~ mm_text: x is incremented by the right direction, Y is incremented in the down direction, we can change the position of the coordinate origin by setViewportorg () and setWindoworg (). Void cinside_vcview :: Ondraw (CDC * PDC) {PDC-> Textout (0, 0, "Test"); PDC-> SelectStockObject (gray_brush); PDC-> setmapmode (mm_text); // PDC-> setWindoworg (100,100) Use this two sentences to see what phenomena // PDC-> setViewPortorg (CPOINT (100, 100)); PDC-> Ellipse (CRECT (0, 0, 300, 300)); PDC-> Textout (0, 0, "22"); } Fixed scale mode: X to the right direction (I think it is increasing), Y, MM_LOENGLISH (0.001 inches) mm_hienglish (0.001 inches) mm_lometric (0.01mm) mm_twips (1/1400 inches, Generally used in printers) variable scale mode: m_isisotropic (1: 1), m_anisotropic (can be arbitrary), set the proportion of setWindowsext () and setViewPortext (), void cinside_vcview :: Ondraw (CDC * PDC) {CRECT rectClient; GetClientRect (rectClient); pDC-> SelectStockObject (m_nColor); pDC-> SetMapMode (MM_ANISOTROPIC); pDC-> SetWindowExt (1000,1000); pDC-> SetViewportExt (rectClient.right, rectClient.bottom); pDC-> SE TViewPortorg (RectClient.Right / 2, RectClient.bottom / 2); PDC-> Ellipse (CRECT (-500, -500, 500, 500));} Physical coordinates, the size of our reality, one inch in the screen is 12 in reality 12 Inch, if we use mm_loenglish (0.01 inches) mapping mode, 26.75 inches will be a computer's 26.75 / 12 = 2.23 (inches), and 1 logical unit in the computer is 0.01 inches, so the 26.75 inches conversion to logical unit is 223 units, but there is omitted in this process, in order to prevent this, we can save them with physical coordinates.
Conversion function; DPTOLP () device coordinate to logical coordinates; lptodp () logical coordinates to device coordinates; physical coordinates to logical coordinates are all calculated by our own;
There are general cases in the MFC: All member functions in the CDC class are used by logical coordinates to do all member functions in the parameter CWnd class. The device coordinates do parameters all selected - Test (HIT-TEST) operation The equipment coordinates are used, and some functions can only use the device coordinates such as: cRect :: PtinRect () All values for long-term saving are generally used logic coordinates, and the user is scrolling with the window to change, the coordinate will be invalid. Next example, the area that tests the left mouse button is not at the specified place Void CMYVIEW :: ONLBUTTONDOWN (CPOINT) {crect Rect = m_Rect; CclientDC DC (this); dc.setmapmode (mm_text); DC; .Lptodp (rect); if (Rect.ptinRect (Point)) {MessageBox ("YES");}
}
General setting mapping mode is more appropriate in onpreparedc () ~ Onpreparedc calls before OnDraw!
The MFC provides a direct message control function for 140 Windows messages, especially pays 5: WM_CREATE, WM_CLOSE, WM_DESTROY, WM_NCDESTROY, WM_QUERYENDSession.
WM_CREATES is the first message sent to the view in Windows, so it cannot call the write-dependent window in OnCreate () completely in the activated Windows function! Generally, it can be called in OnInitialUpdate (), such as: Setting mapping mode ~, but must pay attention, OnInitialUpdate () may be called multiple times between view survival ~