Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to achieve this?? About zoomin/zoomout in CEditView or CEdit...

How to achieve this?? About zoomin/zoomout in CEditView or CEdit...

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutorial
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    figer
    wrote on last edited by
    #1

    I want to add ZoomIn/ZoomOut in my MFC Application, works on text and image, just like MSWORD, how can I get this??:confused::confused: thanks for your response:) -- modified at 22:50 Monday 17th April, 2006

    B 2 Replies Last reply
    0
    • F figer

      I want to add ZoomIn/ZoomOut in my MFC Application, works on text and image, just like MSWORD, how can I get this??:confused::confused: thanks for your response:) -- modified at 22:50 Monday 17th April, 2006

      B Offline
      B Offline
      bob16972
      wrote on last edited by
      #2

      MM_ISOTROPIC will get you zoom with minimal effort. You'll have to work a little though to get an app like MSWORD. I can't help you there.

      1 Reply Last reply
      0
      • F figer

        I want to add ZoomIn/ZoomOut in my MFC Application, works on text and image, just like MSWORD, how can I get this??:confused::confused: thanks for your response:) -- modified at 22:50 Monday 17th April, 2006

        B Offline
        B Offline
        bob16972
        wrote on last edited by
        #3

        Here's a little to get you started. Start a new MFC/SDI app and plop this stuff in the appropriate locations. Set up menu/toolbar buttons for the zoomin/zoomout. Add some drawing code to your OnDraw and you should find that the drawing is fit_to_width in the view and it should be fit to width when printing. The rest is up to you. have fun... (Let me know if I missed something) /////////////////////////////////////////////// //Constants const int MAX_SCALE = 20; // The maximum scale factor //CDocument members... protected: CSize m_DocSize; CSize CYourDoc::GetDocSize() const { return m_DocSize; } CYourDoc::CYourDoc() { // TODO: add one-time construction code here m_DocSize=CSize(2000,2800); } //CScrollView members... protected: int m_Scale; CYourView::CYourView() { // TODO: add construction code here m_Scale=1; // Set scale factor 1:1 SetScrollSizes(MM_TEXT,CSize(0,0)); // Set arbitrary values } void CYourView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) { CScrollView::OnPrepareDC(pDC); // TODO: Add your specialized code here and/or call the base class // Set up the DC for the current scale factor int nExtentX; int nExtentY; CSize sizeDoc; CRect rectClient; // Allows the rectangle to include the bottom and rightmost logical unit // SetGraphicsMode(pDC->m_hDC,GM_ADVANCED); pDC->SetMapMode(MM_ISOTROPIC); // Allow scaling with aspect ratio preserved // Get pertinent rectangle data GetClientRect(&rectClient); sizeDoc=GetDocument()->GetDocSize(); sizeDoc.cy=(-sizeDoc.cy); // Y goes down as it increments pDC->SetWindowExt(sizeDoc); // Window extent is size of document // Calculate viewport extent nExtentX=(int)(GetScale()*rectClient.Width()); nExtentY=(int)((GetScale()*((nExtentX*sizeDoc.cy)/(sizeDoc.cx)))); // What kind of device context do we have? if (pDC->IsPrinting()==TRUE) { // Printer Context. Allow printing to edge of context. No scaling. Margins? pDC->SetViewportExt(pDC->GetDeviceCaps(HORZRES),-pDC->GetDeviceCaps(VERTRES)); } else { // Context is for screen pDC->SetViewportExt(nExtentX,nExtentY); } } int CYourView::GetScale() { return m_Scale; } void CYourView::SetScale(int nScaleFactor) { m_Scale=nScaleFactor; ResetScrollBars(); // Adjust scrollbars to new scale } void CYourView::OnUpdateViewZoomout(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here if (GetScale()>=2) pCmdUI->Enable(TRUE); else pCmdUI->Enable(FALSE); } void CYourVie

        F 2 Replies Last reply
        0
        • B bob16972

          Here's a little to get you started. Start a new MFC/SDI app and plop this stuff in the appropriate locations. Set up menu/toolbar buttons for the zoomin/zoomout. Add some drawing code to your OnDraw and you should find that the drawing is fit_to_width in the view and it should be fit to width when printing. The rest is up to you. have fun... (Let me know if I missed something) /////////////////////////////////////////////// //Constants const int MAX_SCALE = 20; // The maximum scale factor //CDocument members... protected: CSize m_DocSize; CSize CYourDoc::GetDocSize() const { return m_DocSize; } CYourDoc::CYourDoc() { // TODO: add one-time construction code here m_DocSize=CSize(2000,2800); } //CScrollView members... protected: int m_Scale; CYourView::CYourView() { // TODO: add construction code here m_Scale=1; // Set scale factor 1:1 SetScrollSizes(MM_TEXT,CSize(0,0)); // Set arbitrary values } void CYourView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) { CScrollView::OnPrepareDC(pDC); // TODO: Add your specialized code here and/or call the base class // Set up the DC for the current scale factor int nExtentX; int nExtentY; CSize sizeDoc; CRect rectClient; // Allows the rectangle to include the bottom and rightmost logical unit // SetGraphicsMode(pDC->m_hDC,GM_ADVANCED); pDC->SetMapMode(MM_ISOTROPIC); // Allow scaling with aspect ratio preserved // Get pertinent rectangle data GetClientRect(&rectClient); sizeDoc=GetDocument()->GetDocSize(); sizeDoc.cy=(-sizeDoc.cy); // Y goes down as it increments pDC->SetWindowExt(sizeDoc); // Window extent is size of document // Calculate viewport extent nExtentX=(int)(GetScale()*rectClient.Width()); nExtentY=(int)((GetScale()*((nExtentX*sizeDoc.cy)/(sizeDoc.cx)))); // What kind of device context do we have? if (pDC->IsPrinting()==TRUE) { // Printer Context. Allow printing to edge of context. No scaling. Margins? pDC->SetViewportExt(pDC->GetDeviceCaps(HORZRES),-pDC->GetDeviceCaps(VERTRES)); } else { // Context is for screen pDC->SetViewportExt(nExtentX,nExtentY); } } int CYourView::GetScale() { return m_Scale; } void CYourView::SetScale(int nScaleFactor) { m_Scale=nScaleFactor; ResetScrollBars(); // Adjust scrollbars to new scale } void CYourView::OnUpdateViewZoomout(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here if (GetScale()>=2) pCmdUI->Enable(TRUE); else pCmdUI->Enable(FALSE); } void CYourVie

          F Offline
          F Offline
          figer
          wrote on last edited by
          #4

          really appreciate for your answer. I add function TextOut in CMyView::OnDraw(), when I clicked ZoomIn, the view extended it's size, but the text in view still keeped it's size. should I add some other code?

          1 Reply Last reply
          0
          • B bob16972

            Here's a little to get you started. Start a new MFC/SDI app and plop this stuff in the appropriate locations. Set up menu/toolbar buttons for the zoomin/zoomout. Add some drawing code to your OnDraw and you should find that the drawing is fit_to_width in the view and it should be fit to width when printing. The rest is up to you. have fun... (Let me know if I missed something) /////////////////////////////////////////////// //Constants const int MAX_SCALE = 20; // The maximum scale factor //CDocument members... protected: CSize m_DocSize; CSize CYourDoc::GetDocSize() const { return m_DocSize; } CYourDoc::CYourDoc() { // TODO: add one-time construction code here m_DocSize=CSize(2000,2800); } //CScrollView members... protected: int m_Scale; CYourView::CYourView() { // TODO: add construction code here m_Scale=1; // Set scale factor 1:1 SetScrollSizes(MM_TEXT,CSize(0,0)); // Set arbitrary values } void CYourView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) { CScrollView::OnPrepareDC(pDC); // TODO: Add your specialized code here and/or call the base class // Set up the DC for the current scale factor int nExtentX; int nExtentY; CSize sizeDoc; CRect rectClient; // Allows the rectangle to include the bottom and rightmost logical unit // SetGraphicsMode(pDC->m_hDC,GM_ADVANCED); pDC->SetMapMode(MM_ISOTROPIC); // Allow scaling with aspect ratio preserved // Get pertinent rectangle data GetClientRect(&rectClient); sizeDoc=GetDocument()->GetDocSize(); sizeDoc.cy=(-sizeDoc.cy); // Y goes down as it increments pDC->SetWindowExt(sizeDoc); // Window extent is size of document // Calculate viewport extent nExtentX=(int)(GetScale()*rectClient.Width()); nExtentY=(int)((GetScale()*((nExtentX*sizeDoc.cy)/(sizeDoc.cx)))); // What kind of device context do we have? if (pDC->IsPrinting()==TRUE) { // Printer Context. Allow printing to edge of context. No scaling. Margins? pDC->SetViewportExt(pDC->GetDeviceCaps(HORZRES),-pDC->GetDeviceCaps(VERTRES)); } else { // Context is for screen pDC->SetViewportExt(nExtentX,nExtentY); } } int CYourView::GetScale() { return m_Scale; } void CYourView::SetScale(int nScaleFactor) { m_Scale=nScaleFactor; ResetScrollBars(); // Adjust scrollbars to new scale } void CYourView::OnUpdateViewZoomout(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here if (GetScale()>=2) pCmdUI->Enable(TRUE); else pCmdUI->Enable(FALSE); } void CYourVie

            F Offline
            F Offline
            figer
            wrote on last edited by
            #5

            I get it! firt time I failed because I used Textout function without creating a CFont. bob16972,thank you very much!!

            B 1 Reply Last reply
            0
            • F figer

              I get it! firt time I failed because I used Textout function without creating a CFont. bob16972,thank you very much!!

              B Offline
              B Offline
              bob16972
              wrote on last edited by
              #6

              I'm glad it's working. Take care.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups