The fastest and most convenient implementation of CDC use skills to zoom out

xiaoxiao2021-03-06  18

The fastest and most convenient implementation of CDC use skills to zoom out

Today, due to the upgrade of the program, it is necessary to add a zoom function in the original CSCroolView program. It has been pondered for a long time, summarizing the following experience and sharing everyone. Note: The original program is MM_Text mode drawing. Sample code with changes is as follows, the following statement details Void cttttage () {cscrollview :: onInitialupdate ();

CSIZE SIZETAl; // Todo: Calculate The Total Size of this View siz = 30; setscrollsizes (mm_text, sizetate); m_size = sizetotal; // member variable m_size Save View of the original size} // Initialization view Size, here to assume 30void ctttttage code :: onzoom () {// Todo: add your command handler code here csize size = m_size; m_zoom ; // member variable float m_zoom; magnification plus 1 size.cx * = m_zoom; size .cy * = m_zoom; size.cx = 2; size.cy = 2; // may not be the cause of calculating error, always can't see the last few pixels this-> setscrollsizes (mm_text, size); // Set the size of the enlarged rear view This-> invalidate (); // Replay view} // a menu event is zooming

Void cttttview :: initdc (cdc * pdc) {CSIZE SIZE (1000, 1000); // Define the size of the original map, you can freely // but not too small, the larger the number, the higher the accuracy, the higher / raise Example, if the number is 1, zoom in 1.5 times, int (1 * 1.5) = 1 is equal to no enlargement CSIZE NEWSIZE (1000 * m_zoom, 1000 * m_zoom); // After the magnification size onpreparedc (PDC); // PDC Set to bind logical view CPoint Point (0, 0); // Logic view 0 points PDC-> lptodp (& point); // Translate into device coordinates because setViewportorg parameters require equipment coordinates

PDC-> setmapmode (mm_anisotropic); // Set to unit variable mode PDC-> setViewportorg (Point); // Viewport origin is logical view original PDC-> setViewPortext (newsize); // Original window 1000 units correspond to zoom Subunit

PDC-> setWindoworg (0); PDC-> setWindowext (size); //} // Draw DC to set VOID CTTTTVIEW :: OnDraw (CDC * PDC) {ctttdoc * pdoc = getDocument (); assert_valid (PDOC) );

INITDC (PDC); // Setup PDC for new mode

PDC-> MoveTo (30, 30); PDC-> LineTo (0); PDC-> LineTo (30, 0); PDC-> Lineto (30, 30); PDC-> Textout (30, 30, " Text "); // The picture data is unchanged. If you change the PDC mode, you will realize the zoom / / but the text size does not follow the change.} // is better than a detailed introduction, I hope to help everyone. It is also noted that the place to draw in the program may not be a place on DRAW, and some may be CClientDC painting, but you can use initdc to initialize the DC to solve all problems. CSIZE SIZETAl; // Todo: Calculate The Total Size of this View siz = 30; setscrollsizes (mm_text, sizetate); m_size = sizetotal; // member variable m_size Save View of the original size} // Initialization view Size, here to assume 30void ctttttage code :: onzoom () {// Todo: add your command handler code here csize size = m_size; m_zoom ; // member variable float m_zoom; magnification plus 1 size.cx * = m_zoom; size .cy * = m_zoom; size.cx = 2; size.cy = 2; // may not be the cause of calculating error, always can't see the last few pixels this-> setscrollsizes (mm_text, size); // Set the size of the enlarged rear view This-> invalidate (); // Replay view} // a menu event is zooming

Void cttttview :: initdc (cdc * pdc) {CSIZE SIZE (1000, 1000); // Define the size of the original map, you can freely // but not too small, the larger the number, the higher the accuracy, the higher / raise Example, if the number is 1, zoom in 1.5 times, int (1 * 1.5) = 1 is equal to no enlargement CSIZE NEWSIZE (1000 * m_zoom, 1000 * m_zoom); // After the magnification size onpreparedc (PDC); // PDC Set to bind logical view CPoint Point (0, 0); // Logic view 0 points PDC-> lptodp (& point); // Translate into device coordinates because setViewportorg parameters require equipment coordinates

PDC-> setmapmode (mm_anisotropic); // Set to unit variable mode PDC-> setViewportorg (Point); // Viewport origin is logical view original PDC-> setViewPortext (newsize); // Original window 1000 units correspond to zoom Subunit

PDC-> setWindoworg (0); PDC-> setWindowext (size); //} // Draw DC to set VOID CTTTTVIEW :: OnDraw (CDC * PDC) {ctttdoc * pdoc = getDocument (); assert_valid (PDOC) );

INITDC (PDC); // Setup PDC for new mode

转载请注明原文地址:https://www.9cbs.com/read-44165.html

New Post(0)