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. About draw a picture in dialog box

About draw a picture in dialog box

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelpquestion
4 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.
  • L Offline
    L Offline
    lisoft
    wrote on last edited by
    #1

    I have a class that can draw picture in dialog box using the following code: void CDialogbox::OnPaint() { CPaintDC dc(this); // device context for painting CRect m_rect; GetWindowRect(m_rect); //... m_myclass.Draw(dc,m_rect); // Draw the image to dialog box } These codes works fine as I just anticipated. But when I want to use memory DC for caching, it did not work: void CDialogbox::OnPaint() { CPaintDC dc(this); // device context for painting CDC m_memdc; m_memdc.CreateCompatibleDC(&dc); //Create a memory DC CRect m_rect; GetWindowRect(m_rect); //... m_myclass.Draw(dc,m_memdc); // First draw to memory DC dc.BitBlt(m_rect.left,m_rect.right,m_rect.Width(),m_rect.Height(),&m_memdc,0,0,SRCCOPY); // Second copy from memory DC to Paint DC } Does anyone can help me? :confused:

    Lisoft

    L N 2 Replies Last reply
    0
    • L lisoft

      I have a class that can draw picture in dialog box using the following code: void CDialogbox::OnPaint() { CPaintDC dc(this); // device context for painting CRect m_rect; GetWindowRect(m_rect); //... m_myclass.Draw(dc,m_rect); // Draw the image to dialog box } These codes works fine as I just anticipated. But when I want to use memory DC for caching, it did not work: void CDialogbox::OnPaint() { CPaintDC dc(this); // device context for painting CDC m_memdc; m_memdc.CreateCompatibleDC(&dc); //Create a memory DC CRect m_rect; GetWindowRect(m_rect); //... m_myclass.Draw(dc,m_memdc); // First draw to memory DC dc.BitBlt(m_rect.left,m_rect.right,m_rect.Width(),m_rect.Height(),&m_memdc,0,0,SRCCOPY); // Second copy from memory DC to Paint DC } Does anyone can help me? :confused:

      Lisoft

      L Offline
      L Offline
      Le Thanh Cong
      wrote on last edited by
      #2

      m_myclass.Draw(dc,m_memdc); // First draw to memory DC??????????? Why parameter 2 is a DC ----------------- conglt

      1 Reply Last reply
      0
      • L lisoft

        I have a class that can draw picture in dialog box using the following code: void CDialogbox::OnPaint() { CPaintDC dc(this); // device context for painting CRect m_rect; GetWindowRect(m_rect); //... m_myclass.Draw(dc,m_rect); // Draw the image to dialog box } These codes works fine as I just anticipated. But when I want to use memory DC for caching, it did not work: void CDialogbox::OnPaint() { CPaintDC dc(this); // device context for painting CDC m_memdc; m_memdc.CreateCompatibleDC(&dc); //Create a memory DC CRect m_rect; GetWindowRect(m_rect); //... m_myclass.Draw(dc,m_memdc); // First draw to memory DC dc.BitBlt(m_rect.left,m_rect.right,m_rect.Width(),m_rect.Height(),&m_memdc,0,0,SRCCOPY); // Second copy from memory DC to Paint DC } Does anyone can help me? :confused:

        Lisoft

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

        The problem is you did not selected any bitmap to the memdc. CreateCompatibleDC will create a dc with 1x1 pixel wide bitmap. So you have to create a bitmap also. See the example. CPaint dc( this ); CDC dcMem; dcMem.CreateCompatibleDC( &dc ); CBitmap bitmap; bitmap.CreateCompatibleBitmap( &dc, width, height ); CBitmap* pOldBitmap = dcMem.SelectObject( &bitmap ); // // Draw // dc.BitBlt( 0, 0, width, height, &dcMem, 0, 0, SRCCOPY ); dcMem.SelectObject( pOldBitmap ); GoodLuck! - NS -

        L 1 Reply Last reply
        0
        • N Nishad S

          The problem is you did not selected any bitmap to the memdc. CreateCompatibleDC will create a dc with 1x1 pixel wide bitmap. So you have to create a bitmap also. See the example. CPaint dc( this ); CDC dcMem; dcMem.CreateCompatibleDC( &dc ); CBitmap bitmap; bitmap.CreateCompatibleBitmap( &dc, width, height ); CBitmap* pOldBitmap = dcMem.SelectObject( &bitmap ); // // Draw // dc.BitBlt( 0, 0, width, height, &dcMem, 0, 0, SRCCOPY ); dcMem.SelectObject( pOldBitmap ); GoodLuck! - NS -

          L Offline
          L Offline
          lisoft
          wrote on last edited by
          #4

          Thanks a lot, it works! :)

          Lisoft

          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