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. Simple Question

Simple Question

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 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
    SatyaDY
    wrote on last edited by
    #1

    Hi, I am trying put one rectangle in MemDC and bring to screen. Here is the code: CDC MemDC; CClientDC mydc(this); MemDC.CreateCompatibleDC(&mydc); MemDC.Rectagble(&myrect); MemDC.SelectObject(&mybrush); /////myrect and mybrush I created before MemDC.FillRect(&myrect,&mybrush); mydc.BitBlt(0,0,1024,768,&MemDC,0,0,SRCCOPY); But I am not finding any output. Help me. Thanks Satya

    J J 2 Replies Last reply
    0
    • S SatyaDY

      Hi, I am trying put one rectangle in MemDC and bring to screen. Here is the code: CDC MemDC; CClientDC mydc(this); MemDC.CreateCompatibleDC(&mydc); MemDC.Rectagble(&myrect); MemDC.SelectObject(&mybrush); /////myrect and mybrush I created before MemDC.FillRect(&myrect,&mybrush); mydc.BitBlt(0,0,1024,768,&MemDC,0,0,SRCCOPY); But I am not finding any output. Help me. Thanks Satya

      J Offline
      J Offline
      jason99
      wrote on last edited by
      #2

      This can't work...you have to construct a compatible bitmap and select it into the memory DC. At the moment, you are simply drawing on "nothing"...and "nothing" is what you are bitblitting. greets, Jason

      S 1 Reply Last reply
      0
      • J jason99

        This can't work...you have to construct a compatible bitmap and select it into the memory DC. At the moment, you are simply drawing on "nothing"...and "nothing" is what you are bitblitting. greets, Jason

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

        Hi, Where I have to include that Compatible Bitmap?? That means I have to draw the things on the bitmap and move this to memory and bitblt to screen?? Can U please give some explanation, Regards Satya

        B 1 Reply Last reply
        0
        • S SatyaDY

          Hi, Where I have to include that Compatible Bitmap?? That means I have to draw the things on the bitmap and move this to memory and bitblt to screen?? Can U please give some explanation, Regards Satya

          B Offline
          B Offline
          Brian Shifrin
          wrote on last edited by
          #4

          >CDC MemDC; >CClientDC mydc(this); CBitmap bmMem; >MemDC.CreateCompatibleDC(&mydc); if (bmMem.CreateCompatibleBitmap(&mydc, nWidth, nHeight)) { CBitmap* pOldBM = MemDC.SelectObject(&bmMem); >MemDC.Rectagble(&myrect); >MemDC.SelectObject(&mybrush); /////myrect and mybrush I created before >MemDC.FillRect(&myrect,&mybrush); >mydc.BitBlt(0,0,1024,768,&MemDC,0,0,SRCCOPY); MemDC.SelectObject(pOldBM); }

          J 1 Reply Last reply
          0
          • B Brian Shifrin

            >CDC MemDC; >CClientDC mydc(this); CBitmap bmMem; >MemDC.CreateCompatibleDC(&mydc); if (bmMem.CreateCompatibleBitmap(&mydc, nWidth, nHeight)) { CBitmap* pOldBM = MemDC.SelectObject(&bmMem); >MemDC.Rectagble(&myrect); >MemDC.SelectObject(&mybrush); /////myrect and mybrush I created before >MemDC.FillRect(&myrect,&mybrush); >mydc.BitBlt(0,0,1024,768,&MemDC,0,0,SRCCOPY); MemDC.SelectObject(pOldBM); }

            J Offline
            J Offline
            jason99
            wrote on last edited by
            #5

            Hi, Yes that should do it!

            1 Reply Last reply
            0
            • S SatyaDY

              Hi, I am trying put one rectangle in MemDC and bring to screen. Here is the code: CDC MemDC; CClientDC mydc(this); MemDC.CreateCompatibleDC(&mydc); MemDC.Rectagble(&myrect); MemDC.SelectObject(&mybrush); /////myrect and mybrush I created before MemDC.FillRect(&myrect,&mybrush); mydc.BitBlt(0,0,1024,768,&MemDC,0,0,SRCCOPY); But I am not finding any output. Help me. Thanks Satya

              J Offline
              J Offline
              John R Shaw
              wrote on last edited by
              #6

              //Looks like you want to do flicker free drawing //Which is the only reason for doing this CDC MemDC; CBitmap bmp; CClientDC mydc(this); MemDC.CreateCompatibleDC(&mydc); bmp.CreateCompatibleBitmap(&mydc,1024,768); CBitmap* pOldBmp = MemDC.SelectObject(&bmp); // Draw rectangle CBrush* pOldBrush = MemDC.SelectObject(&mybrush); MemDC.Rectangle(myrect); MemDC.SelectObject(&pOldBrush); //TODO: Draw other things //Blit to client DC mydc.BitBlt(0,0,1024,768,&MemDC,0,0,SRCCOPY); //Clean up MemDC.SelectObject(&pOldBmp); MemDC.DeleteDC(); Doing all of the above when you receive a WM_PAINT message is the slow way, but it works. Find the article "Do a flicker-free drawing using MFC methods" here at codeproject. I have not read it but it should provide you with your answers. Trust in the code Luke. Yea right!

              S 1 Reply Last reply
              0
              • J John R Shaw

                //Looks like you want to do flicker free drawing //Which is the only reason for doing this CDC MemDC; CBitmap bmp; CClientDC mydc(this); MemDC.CreateCompatibleDC(&mydc); bmp.CreateCompatibleBitmap(&mydc,1024,768); CBitmap* pOldBmp = MemDC.SelectObject(&bmp); // Draw rectangle CBrush* pOldBrush = MemDC.SelectObject(&mybrush); MemDC.Rectangle(myrect); MemDC.SelectObject(&pOldBrush); //TODO: Draw other things //Blit to client DC mydc.BitBlt(0,0,1024,768,&MemDC,0,0,SRCCOPY); //Clean up MemDC.SelectObject(&pOldBmp); MemDC.DeleteDC(); Doing all of the above when you receive a WM_PAINT message is the slow way, but it works. Find the article "Do a flicker-free drawing using MFC methods" here at codeproject. I have not read it but it should provide you with your answers. Trust in the code Luke. Yea right!

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

                Thank U all for the replies I got it. Regards :-) Satya

                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