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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. using BitBlt for preview DC

using BitBlt for preview DC

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelp
20 Posts 5 Posters 1 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.
  • _ _T No name

    hi i m using BitBlt for preview dc my drawing coming distorted while in normal display it comes proper. i have used memDC for drawing and using BitBlt for copying on display dc. i have to use memDC to avoid flickering. used StrechDibits also same result. Plz help and suggest me flicker free solution. thnks

    H Offline
    H Offline
    Hamid Taebi
    wrote on last edited by
    #3

    Flicker free drawing without using double buffer[^] GDI Topics: Flicker-Free Drawing[^] Flicker free drawing using memory DC[^].

    Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )

    _ 1 Reply Last reply
    0
    • H Hamid Taebi

      Flicker free drawing without using double buffer[^] GDI Topics: Flicker-Free Drawing[^] Flicker free drawing using memory DC[^].

      Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )

      _ Offline
      _ Offline
      _T No name
      wrote on last edited by
      #4

      i think u didnt get me.. i have used memDC fot flicker free drwaing but it does not work in case PrintPreview. I have used BitBlt for copying from memDC to pDC. But not in case of print preivw. if i do drawing does not come properly. i think there is some problem with BitBlt in case of preview DC. thanks

      C 1 Reply Last reply
      0
      • _ _T No name

        i think u didnt get me.. i have used memDC fot flicker free drwaing but it does not work in case PrintPreview. I have used BitBlt for copying from memDC to pDC. But not in case of print preivw. if i do drawing does not come properly. i think there is some problem with BitBlt in case of preview DC. thanks

        C Offline
        C Offline
        Code o mat
        wrote on last edited by
        #5

        What exactly do you mean by

        _T("No name") wrote:

        drawing does not come properly

        ? Maybe put up some code or -don't know if it is possible or allowed or a nice thing to do- screenshots or maybe links to screenshots for us to see what you mean.

        > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

        _ 1 Reply Last reply
        0
        • _ _T No name

          hi i m using BitBlt for preview dc my drawing coming distorted while in normal display it comes proper. i have used memDC for drawing and using BitBlt for copying on display dc. i have to use memDC to avoid flickering. used StrechDibits also same result. Plz help and suggest me flicker free solution. thnks

          N Offline
          N Offline
          Nishad S
          wrote on last edited by
          #6

          _T("No name") wrote:

          my drawing coming distorted

          What you meant by distorted? You may try SetStretchBltMode, with HALFTONE, then use StretchBlt. (If my guess is correct... :) )

          - ns -

          _ 1 Reply Last reply
          0
          • C Code o mat

            What exactly do you mean by

            _T("No name") wrote:

            drawing does not come properly

            ? Maybe put up some code or -don't know if it is possible or allowed or a nice thing to do- screenshots or maybe links to screenshots for us to see what you mean.

            > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

            _ Offline
            _ Offline
            _T No name
            wrote on last edited by
            #7

            void CCalendarControlView::DrawOnDC(CDC * pDC, int isPrinting) { if (pDC->IsKindOf(RUNTIME_CLASS(CPreviewDC))) { memDC.CreateCompatibleDC(pDC); bmp.CreateCompatibleBitmap(pDC, rc.Width(),rc.height()); memDC.SelectObject(&bmp); pMemDC = &memDC; } //Now m doing some drawing on pMemDc and at last after drawing for display pDC->BitBlt(0,0,rc.Width(),rc.Height(),pMemDC,SRCCOPY); } and onPrintPreviewButtton() { AFXPrintPreview(this); } m doing this getting correct drawig in case of niormal display but not in case or print preivew.

            C 1 Reply Last reply
            0
            • N Nishad S

              _T("No name") wrote:

              my drawing coming distorted

              What you meant by distorted? You may try SetStretchBltMode, with HALFTONE, then use StretchBlt. (If my guess is correct... :) )

              - ns -

              _ Offline
              _ Offline
              _T No name
              wrote on last edited by
              #8

              i tried this also this didnt help. i have uploaded the code i think this will help u thx

              1 Reply Last reply
              0
              • _ _T No name

                void CCalendarControlView::DrawOnDC(CDC * pDC, int isPrinting) { if (pDC->IsKindOf(RUNTIME_CLASS(CPreviewDC))) { memDC.CreateCompatibleDC(pDC); bmp.CreateCompatibleBitmap(pDC, rc.Width(),rc.height()); memDC.SelectObject(&bmp); pMemDC = &memDC; } //Now m doing some drawing on pMemDc and at last after drawing for display pDC->BitBlt(0,0,rc.Width(),rc.Height(),pMemDC,SRCCOPY); } and onPrintPreviewButtton() { AFXPrintPreview(this); } m doing this getting correct drawig in case of niormal display but not in case or print preivew.

                C Offline
                C Offline
                Code o mat
                wrote on last edited by
                #9

                Explain what your print preview looks like. You could try using SetAttribDC[^] or SetOutputDC[^], but without seeing your results i am just guessing around.

                > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

                _ 1 Reply Last reply
                0
                • C Code o mat

                  Explain what your print preview looks like. You could try using SetAttribDC[^] or SetOutputDC[^], but without seeing your results i am just guessing around.

                  > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

                  _ Offline
                  _ Offline
                  _T No name
                  wrote on last edited by
                  #10

                  i was getting some thing earlier. but now with the code i have given u m nt getting nything. on Print preview it just comes while page. did u got the code write in that code i have just written the case of preview DC thanx

                  C 1 Reply Last reply
                  0
                  • _ _T No name

                    i was getting some thing earlier. but now with the code i have given u m nt getting nything. on Print preview it just comes while page. did u got the code write in that code i have just written the case of preview DC thanx

                    C Offline
                    C Offline
                    Code o mat
                    wrote on last edited by
                    #11

                    Pardon?

                    > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

                    _ 1 Reply Last reply
                    0
                    • C Code o mat

                      Pardon?

                      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

                      _ Offline
                      _ Offline
                      _T No name
                      wrote on last edited by
                      #12

                      did u get the code i have pasted. i m nt getting wt u have understood and wt u didnt. void CCalendarControlView::OnFilePrintPreview() { AFXPrintPreview(this); } CRect rc = rcClient; void CCalendarControlView::DrawOnDC(CDC * pDC, int isPrinting) { memDC.CreateCompatibleDC(pDC); bmp.CreateCompatibleBitmap(pDC, rc.Width(), rc.Height()); memDC.SelectObject(&bmp); pMemDC = &memDC; } //Now drawinf something on pMemDC //Now BitBlt pDC->BitBlt(0, 0, rc.Width(), rc.Height(), pMemDC, 0, 0, SRCCOPY); this works fine in case of display in window but nuthing comes on OnFilePrintPreview() if ny prob in getting code please let me knw.. thanx for ur effort

                      C 1 Reply Last reply
                      0
                      • _ _T No name

                        did u get the code i have pasted. i m nt getting wt u have understood and wt u didnt. void CCalendarControlView::OnFilePrintPreview() { AFXPrintPreview(this); } CRect rc = rcClient; void CCalendarControlView::DrawOnDC(CDC * pDC, int isPrinting) { memDC.CreateCompatibleDC(pDC); bmp.CreateCompatibleBitmap(pDC, rc.Width(), rc.Height()); memDC.SelectObject(&bmp); pMemDC = &memDC; } //Now drawinf something on pMemDC //Now BitBlt pDC->BitBlt(0, 0, rc.Width(), rc.Height(), pMemDC, 0, 0, SRCCOPY); this works fine in case of display in window but nuthing comes on OnFilePrintPreview() if ny prob in getting code please let me knw.. thanx for ur effort

                        C Offline
                        C Offline
                        Code o mat
                        wrote on last edited by
                        #13

                        Google doesn't bring up much for AFXPrintPreview, and i don't know it. Are you sure your drawing code gets called when you call that AFXPrintPreview method?

                        > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

                        _ 1 Reply Last reply
                        0
                        • C Code o mat

                          Google doesn't bring up much for AFXPrintPreview, and i don't know it. Are you sure your drawing code gets called when you call that AFXPrintPreview method?

                          > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

                          _ Offline
                          _ Offline
                          _T No name
                          wrote on last edited by
                          #14

                          ya i m sure as it works perfectly in case i do not use memery dc in case of print preview and directly do the drawing on display dc. actually it is given in mfc itself all the code DoPrintPreview and CPrintDialog etc code has been written and these functions is being called. if it works in case display dc i dnt knw why it doesnt work in case of memory dc and copying to display dc thanks for ur effort.

                          C 1 Reply Last reply
                          0
                          • _ _T No name

                            ya i m sure as it works perfectly in case i do not use memery dc in case of print preview and directly do the drawing on display dc. actually it is given in mfc itself all the code DoPrintPreview and CPrintDialog etc code has been written and these functions is being called. if it works in case display dc i dnt knw why it doesnt work in case of memory dc and copying to display dc thanks for ur effort.

                            C Offline
                            C Offline
                            Code o mat
                            wrote on last edited by
                            #15

                            Your problem might be the rectangle you use for the drawing. Could it be that your buffer bitmap does not get the right size? Also, doing a print preview isn't exactly the same as drawing on the screen, as far as i know, since printers have different page sizes, DPIs, whatevers, if i were you i would try experimenting with that SetAttribDC[^], try doing MemDC.SetAttribDC(pDC) before you start drawing and MemDC.ReleaseAttribDC()[^] afterwards and see if anything changes.

                            > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

                            _ 1 Reply Last reply
                            0
                            • C Code o mat

                              Your problem might be the rectangle you use for the drawing. Could it be that your buffer bitmap does not get the right size? Also, doing a print preview isn't exactly the same as drawing on the screen, as far as i know, since printers have different page sizes, DPIs, whatevers, if i were you i would try experimenting with that SetAttribDC[^], try doing MemDC.SetAttribDC(pDC) before you start drawing and MemDC.ReleaseAttribDC()[^] afterwards and see if anything changes.

                              > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

                              _ Offline
                              _ Offline
                              _T No name
                              wrote on last edited by
                              #16

                              well i did that also but that didnt help. even wt u r telling can be a case but how to get correct size i just have the info that in case if print preview the pDC i get in OnDraw() is the one with m_bPrinting = 1 means its a printer dc. it might be due to AFXPrintPreview() it runs some code written in mfc itself in viewcore.cpp viewprev.cpp. u might have these files also if u have latest visual studio at C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\src\mfc ny idea how can i check the size m passing to buffer dc is correct or not thanks

                              C 1 Reply Last reply
                              0
                              • _ _T No name

                                well i did that also but that didnt help. even wt u r telling can be a case but how to get correct size i just have the info that in case if print preview the pDC i get in OnDraw() is the one with m_bPrinting = 1 means its a printer dc. it might be due to AFXPrintPreview() it runs some code written in mfc itself in viewcore.cpp viewprev.cpp. u might have these files also if u have latest visual studio at C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\src\mfc ny idea how can i check the size m passing to buffer dc is correct or not thanks

                                C Offline
                                C Offline
                                Code o mat
                                wrote on last edited by
                                #17

                                Try using CDC::GetDeviceCaps[^], giving it maybe HORZRES and VERTRES or so to get the size of the DC's surface, or maybe HORZSIZE and VERTSIZE. Just note something, when using printer DC's, the size of the surface might be HUGE. Actually, do you really need to draw your print preview on a buffer?

                                > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

                                _ 1 Reply Last reply
                                0
                                • C Code o mat

                                  Try using CDC::GetDeviceCaps[^], giving it maybe HORZRES and VERTRES or so to get the size of the DC's surface, or maybe HORZSIZE and VERTSIZE. Just note something, when using printer DC's, the size of the surface might be HUGE. Actually, do you really need to draw your print preview on a buffer?

                                  > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

                                  _ Offline
                                  _ Offline
                                  _T No name
                                  wrote on last edited by
                                  #18

                                  i have did this. even though prob is same nothing is coming. i have to use buffer as there is so much flicering comin in print preview window as resizing and all due to direct drawing on display dc. if (pDC->IsKindOf(RUNTIME_CLASS(CPreviewDC))) { //using buffer and copying from mem DC to preview DC causes problem. so //we directly draw on preview DC during preview. memDC.CreateCompatibleDC(pDC); bmp.CreateCompatibleBitmap(pDC, pDC->GetDeviceCaps(HORZRES), pDC->;GetDeviceCaps(VERTRES)); memDC.SelectObject(&bmp); memDC.SetAttribDC(pDC->;GetSafeHdc()); //pMemDC = pDC; pMemDC = &memDC; }

                                  C _ 2 Replies Last reply
                                  0
                                  • _ _T No name

                                    i have did this. even though prob is same nothing is coming. i have to use buffer as there is so much flicering comin in print preview window as resizing and all due to direct drawing on display dc. if (pDC->IsKindOf(RUNTIME_CLASS(CPreviewDC))) { //using buffer and copying from mem DC to preview DC causes problem. so //we directly draw on preview DC during preview. memDC.CreateCompatibleDC(pDC); bmp.CreateCompatibleBitmap(pDC, pDC->GetDeviceCaps(HORZRES), pDC->;GetDeviceCaps(VERTRES)); memDC.SelectObject(&bmp); memDC.SetAttribDC(pDC->;GetSafeHdc()); //pMemDC = pDC; pMemDC = &memDC; }

                                    C Offline
                                    C Offline
                                    Code o mat
                                    wrote on last edited by
                                    #19

                                    Does BitBlt succeed at all?

                                    > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

                                    1 Reply Last reply
                                    0
                                    • _ _T No name

                                      i have did this. even though prob is same nothing is coming. i have to use buffer as there is so much flicering comin in print preview window as resizing and all due to direct drawing on display dc. if (pDC->IsKindOf(RUNTIME_CLASS(CPreviewDC))) { //using buffer and copying from mem DC to preview DC causes problem. so //we directly draw on preview DC during preview. memDC.CreateCompatibleDC(pDC); bmp.CreateCompatibleBitmap(pDC, pDC->GetDeviceCaps(HORZRES), pDC->;GetDeviceCaps(VERTRES)); memDC.SelectObject(&bmp); memDC.SetAttribDC(pDC->;GetSafeHdc()); //pMemDC = pDC; pMemDC = &memDC; }

                                      _ Offline
                                      _ Offline
                                      _T No name
                                      wrote on last edited by
                                      #20

                                      yes it does in both the case (display and print preview) the rc i m passing to bitblt and CreateCompatibleBmp is of 6400 ,4900 i think this is the one u were talking abt so its correct right ?? in case of printing m already setting m_rcPrintrect as above size

                                      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