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. Update WM_PAINT and Memory DC

Update WM_PAINT and Memory DC

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsperformancetutorialquestionannouncement
6 Posts 3 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.
  • H Offline
    H Offline
    HTT90
    wrote on last edited by
    #1

    Hi All , I have a code :

    int CExWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    if(CWnd::OnCreate(lpCreateStruct)==-1) return -1;
    CClientDC dc(this);
    pDC.CreateCompatibleDC(&dc);
    bitmap.CreateCompatibleBitmap(&dc,Width,Height);
    pDC.SelectObject(&bitmap);
    return 0;
    }
    void CExWnd::OnPaint()
    {
    CClientDC dc(this); // here
    Draw ( pDC ) ;
    dc.BitBlt(0,0,Width,Height,&pDC,0,0,SRCCOPY);
    }

    This is a example . I have a question . Why WM_PAINT auto update when compatible with pDC . ( the same CClientDC ) . I'm not good at English . Sorry !! Thanks .

    N 1 Reply Last reply
    0
    • H HTT90

      Hi All , I have a code :

      int CExWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
      {
      if(CWnd::OnCreate(lpCreateStruct)==-1) return -1;
      CClientDC dc(this);
      pDC.CreateCompatibleDC(&dc);
      bitmap.CreateCompatibleBitmap(&dc,Width,Height);
      pDC.SelectObject(&bitmap);
      return 0;
      }
      void CExWnd::OnPaint()
      {
      CClientDC dc(this); // here
      Draw ( pDC ) ;
      dc.BitBlt(0,0,Width,Height,&pDC,0,0,SRCCOPY);
      }

      This is a example . I have a question . Why WM_PAINT auto update when compatible with pDC . ( the same CClientDC ) . I'm not good at English . Sorry !! Thanks .

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

      The underlying DC in your CClientDC is where the drawing gets visible. You can use temporary DC's to do painting, but then you will have to transfer it to the 'visual' DC. That's what the BitBlt call is doing.

      home

      H 1 Reply Last reply
      0
      • N Niklas L

        The underlying DC in your CClientDC is where the drawing gets visible. You can use temporary DC's to do painting, but then you will have to transfer it to the 'visual' DC. That's what the BitBlt call is doing.

        home

        H Offline
        H Offline
        HTT90
        wrote on last edited by
        #3

        Can you share for me documentary about it ? Thanks .

        N 1 Reply Last reply
        0
        • H HTT90

          Can you share for me documentary about it ? Thanks .

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

          You can start by reading about device contexts here[^]

          home

          H 1 Reply Last reply
          0
          • N Niklas L

            You can start by reading about device contexts here[^]

            home

            H Offline
            H Offline
            HTT90
            wrote on last edited by
            #5

            I read but i don't understand what you say . :( . I will try . Thanks .

            J 1 Reply Last reply
            0
            • H HTT90

              I read but i don't understand what you say . :( . I will try . Thanks .

              J Offline
              J Offline
              JohnCz
              wrote on last edited by
              #6

              It is indeed really weird. It looks like CClientDC directly or indirectly causes window to redraw in turn causing constant flow of WM_PAINT messages. Even wierder, you can remove BitBlt from OnPaint and window will still redraw, providing your code is equivalent to mine. This is a toughest question I have ever encountered on many discussion forums. I have quickly tested your code on Vista and so far I did not find any answers. I am looking into it and when (if) I find and answer it will be a real satisfaction. Later, I am also going to test it on XP and Windows 7.

              JohnCz MS C++ MVP

              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