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. Margin like MSWord in CView

Margin like MSWord in CView

Scheduled Pinned Locked Moved C / C++ / MFC
9 Posts 4 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.
  • S Offline
    S Offline
    sanskypotov
    wrote on last edited by
    #1

    Hi, I want to have margins like MSWord in my CView, i.e there should be Grey area around the document , in which we cannot type anything. Can someone tell me how it can be done. Thanks Sansky:-D God is Good, all the Time. All the Time, God is Good.

    N 1 Reply Last reply
    0
    • S sanskypotov

      Hi, I want to have margins like MSWord in my CView, i.e there should be Grey area around the document , in which we cannot type anything. Can someone tell me how it can be done. Thanks Sansky:-D God is Good, all the Time. All the Time, God is Good.

      N Offline
      N Offline
      Niklas L
      wrote on last edited by
      #2

      How about

      CBrush* pBrush = CDC::GetHalftoneBrush();
      CBrush* pBrushOld = pDC->SelectObject(pBrush);
      CRect rc;
      GetClientRect(&rc);
      pDC->PatBlt(rc.left, rc.top, rc.Width(), rc.Height(), PATCOPY);

      pDC->SelectObject(pBrushOld);

      in your view's OnEraseBkGnd()?

      S 1 Reply Last reply
      0
      • N Niklas L

        How about

        CBrush* pBrush = CDC::GetHalftoneBrush();
        CBrush* pBrushOld = pDC->SelectObject(pBrush);
        CRect rc;
        GetClientRect(&rc);
        pDC->PatBlt(rc.left, rc.top, rc.Width(), rc.Height(), PATCOPY);

        pDC->SelectObject(pBrushOld);

        in your view's OnEraseBkGnd()?

        S Offline
        S Offline
        sanskypotov
        wrote on last edited by
        #3

        Hi, Thanks for the Reply, Actually how it should be is , The user has to be restricted to part of CView, he cannot type anything in the margin. Example MSWord, or Print Preview Thanks Sansky :-D God is Good, all the Time. All the Time, God is Good.

        M 1 Reply Last reply
        0
        • S sanskypotov

          Hi, Thanks for the Reply, Actually how it should be is , The user has to be restricted to part of CView, he cannot type anything in the margin. Example MSWord, or Print Preview Thanks Sansky :-D God is Good, all the Time. All the Time, God is Good.

          M Offline
          M Offline
          Matt Gullett
          wrote on last edited by
          #4

          The easisest way to make this work would be to overide your frame class and position the view X pixels to the left of the frame left. Then, in your frame class (OnPaint), paint the left area the color your want. In its simplest form it would look something like:

          BOOL CMyFrame::OnCreateClient(bla.bla.bla)
          {
          if (!CBaseFrameClass::OnCreateClient(bla.bla.bla))
          return FALSE;

          PostMessage(WM_SIZE);
          }

          BOOL CMyFrame::OnSize(bla.bla.bla)
          {
          if (m_pViewActive)
          {
          CRect ClientRect;
          GetClientRect(ClientRect);

            m\_pViewActive->SetWindowPos(NULL, 
                           \[margin-width\], 
                           0, ClientRect.Widht()-\[margin-width\],
                           ClientRect.Height(), 
                           0);
          

          }
          }

          void CMyFrame::OnPaint()
          {
          CPaintDC dc(this);
          CRect ClientRect;
          GetClientRect(ClientRect);

          dc.FillSolidRect(0,
          0, [margin-width],
          ClientRect.Height(),
          [some-color]);
          }

          I did this code from memory so there are probably some errors, but basically should work.

          S 1 Reply Last reply
          0
          • M Matt Gullett

            The easisest way to make this work would be to overide your frame class and position the view X pixels to the left of the frame left. Then, in your frame class (OnPaint), paint the left area the color your want. In its simplest form it would look something like:

            BOOL CMyFrame::OnCreateClient(bla.bla.bla)
            {
            if (!CBaseFrameClass::OnCreateClient(bla.bla.bla))
            return FALSE;

            PostMessage(WM_SIZE);
            }

            BOOL CMyFrame::OnSize(bla.bla.bla)
            {
            if (m_pViewActive)
            {
            CRect ClientRect;
            GetClientRect(ClientRect);

              m\_pViewActive->SetWindowPos(NULL, 
                             \[margin-width\], 
                             0, ClientRect.Widht()-\[margin-width\],
                             ClientRect.Height(), 
                             0);
            

            }
            }

            void CMyFrame::OnPaint()
            {
            CPaintDC dc(this);
            CRect ClientRect;
            GetClientRect(ClientRect);

            dc.FillSolidRect(0,
            0, [margin-width],
            ClientRect.Height(),
            [some-color]);
            }

            I did this code from memory so there are probably some errors, but basically should work.

            S Offline
            S Offline
            sanskypotov
            wrote on last edited by
            #5

            Hi, Thanks for the answer, I tried the code, which runs fine , but one problem remains is , How do I find the Height of the View, because if there are multiple Toolbars, ( esp. which can be dynamically aligned ), how do I calculate the height, also I have to consider the StatusBar. Because when I do GetClientRect(...), then it gives me the top, left as 0 (Zero ). Please can you help me here Thanks, Sanksy :-D God is Good, all the Time. All the Time, God is Good.

            M R 2 Replies Last reply
            0
            • S sanskypotov

              Hi, Thanks for the answer, I tried the code, which runs fine , but one problem remains is , How do I find the Height of the View, because if there are multiple Toolbars, ( esp. which can be dynamically aligned ), how do I calculate the height, also I have to consider the StatusBar. Because when I do GetClientRect(...), then it gives me the top, left as 0 (Zero ). Please can you help me here Thanks, Sanksy :-D God is Good, all the Time. All the Time, God is Good.

              M Offline
              M Offline
              Matt Gullett
              wrote on last edited by
              #6

              So you have a toolbar and status bar on your view's frame? Or just on your main frame window? If you are using traditional MDI you probably just have it on your main frame window and the GetClientRect call in your child's frame window will return the correct values. If you are using MTI, FDI or have toolbars on your child frame you will need to look at the RepositionBars function (CWnd? member I think?). I don't have access to my development PC at the moment, but I think this is right.

              S 1 Reply Last reply
              0
              • M Matt Gullett

                So you have a toolbar and status bar on your view's frame? Or just on your main frame window? If you are using traditional MDI you probably just have it on your main frame window and the GetClientRect call in your child's frame window will return the correct values. If you are using MTI, FDI or have toolbars on your child frame you will need to look at the RepositionBars function (CWnd? member I think?). I don't have access to my development PC at the moment, but I think this is right.

                S Offline
                S Offline
                sanskypotov
                wrote on last edited by
                #7

                Thanks, I will check and let you know. Regards, Sansky :-D God is Good, all the Time. All the Time, God is Good.

                1 Reply Last reply
                0
                • S sanskypotov

                  Hi, Thanks for the answer, I tried the code, which runs fine , but one problem remains is , How do I find the Height of the View, because if there are multiple Toolbars, ( esp. which can be dynamically aligned ), how do I calculate the height, also I have to consider the StatusBar. Because when I do GetClientRect(...), then it gives me the top, left as 0 (Zero ). Please can you help me here Thanks, Sanksy :-D God is Good, all the Time. All the Time, God is Good.

                  R Offline
                  R Offline
                  Roman Nurik
                  wrote on last edited by
                  #8

                  check RecalcLayout and use the range 0 to 0xFFFF for the control bars... and check the flags in MSDN to calculate the total client rect and not actually do the GUI

                  - Roman -

                  S 1 Reply Last reply
                  0
                  • R Roman Nurik

                    check RecalcLayout and use the range 0 to 0xFFFF for the control bars... and check the flags in MSDN to calculate the total client rect and not actually do the GUI

                    - Roman -

                    S Offline
                    S Offline
                    sanskypotov
                    wrote on last edited by
                    #9

                    Thanks for the reply, but please can you give more details . Regards, Sansky :-D God is Good, all the Time. All the Time, God is Good.

                    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