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. Why cannot I get a DC of a window in sometime after a longtime running

Why cannot I get a DC of a window in sometime after a longtime running

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

    Hi All,I have some trouble: The symptom is I have a child window(CStatic)to display status information,it must be updated every second,after a longtime running(maybe 20 minute),then i only got a NULL DC pointer,and then system give me a notification that the resource requred can't acquire.at the same time get into mass. Any help will be appreciated. some representive code(in a method of a CStatic derived class): CDC* pDC=NULL; pDC=GetDC(); if(pDC==NULL) { TRACE("Draw Label Failed!\n"); return FALSE; } CRect rc; if(::GetClientRect(m_hWnd,&rc)) { PaintBk(pDC,rc); int iDC=pDC->SaveDC(); pDC->SetBkColor(0); pDC->SetTextColor(m_FontColor); pDC->SelectObject(&m_Font); pDC->DrawText(m_szLabel,&rc,DT_VCENTER|DT_SINGLELINE); pDC->RestoreDC(iDC); return TRUE; } Scratch

    P S 2 Replies Last reply
    0
    • L Lizp

      Hi All,I have some trouble: The symptom is I have a child window(CStatic)to display status information,it must be updated every second,after a longtime running(maybe 20 minute),then i only got a NULL DC pointer,and then system give me a notification that the resource requred can't acquire.at the same time get into mass. Any help will be appreciated. some representive code(in a method of a CStatic derived class): CDC* pDC=NULL; pDC=GetDC(); if(pDC==NULL) { TRACE("Draw Label Failed!\n"); return FALSE; } CRect rc; if(::GetClientRect(m_hWnd,&rc)) { PaintBk(pDC,rc); int iDC=pDC->SaveDC(); pDC->SetBkColor(0); pDC->SetTextColor(m_FontColor); pDC->SelectObject(&m_Font); pDC->DrawText(m_szLabel,&rc,DT_VCENTER|DT_SINGLELINE); pDC->RestoreDC(iDC); return TRUE; } Scratch

      P Offline
      P Offline
      Paul M Watt
      wrote on last edited by
      #2

      Since your CDC class is a pointer, you need to delete it to free the resources that it contains. ... if(::GetClientRect(m_hWnd,&rc)) { PaintBk(pDC,rc); int iDC=pDC->SaveDC(); pDC->SetBkColor(0); pDC->SetTextColor(m_FontColor); pDC->SelectObject(&m_Font); pDC->DrawText(m_szLabel,&rc,DT_VCENTER|DT_SINGLELINE); pDC->RestoreDC(iDC); delete pDC return TRUE; }

      L 2 Replies Last reply
      0
      • P Paul M Watt

        Since your CDC class is a pointer, you need to delete it to free the resources that it contains. ... if(::GetClientRect(m_hWnd,&rc)) { PaintBk(pDC,rc); int iDC=pDC->SaveDC(); pDC->SetBkColor(0); pDC->SetTextColor(m_FontColor); pDC->SelectObject(&m_Font); pDC->DrawText(m_szLabel,&rc,DT_VCENTER|DT_SINGLELINE); pDC->RestoreDC(iDC); delete pDC return TRUE; }

        L Offline
        L Offline
        Lizp
        wrote on last edited by
        #3

        Thank you,I will try it. Scratch

        1 Reply Last reply
        0
        • L Lizp

          Hi All,I have some trouble: The symptom is I have a child window(CStatic)to display status information,it must be updated every second,after a longtime running(maybe 20 minute),then i only got a NULL DC pointer,and then system give me a notification that the resource requred can't acquire.at the same time get into mass. Any help will be appreciated. some representive code(in a method of a CStatic derived class): CDC* pDC=NULL; pDC=GetDC(); if(pDC==NULL) { TRACE("Draw Label Failed!\n"); return FALSE; } CRect rc; if(::GetClientRect(m_hWnd,&rc)) { PaintBk(pDC,rc); int iDC=pDC->SaveDC(); pDC->SetBkColor(0); pDC->SetTextColor(m_FontColor); pDC->SelectObject(&m_Font); pDC->DrawText(m_szLabel,&rc,DT_VCENTER|DT_SINGLELINE); pDC->RestoreDC(iDC); return TRUE; } Scratch

          S Offline
          S Offline
          Stan Shannon
          wrote on last edited by
          #4

          I think you simply need to do ReleaseDC( pDC ); "There's a slew of slip 'twixt cup and lip"

          1 Reply Last reply
          0
          • P Paul M Watt

            Since your CDC class is a pointer, you need to delete it to free the resources that it contains. ... if(::GetClientRect(m_hWnd,&rc)) { PaintBk(pDC,rc); int iDC=pDC->SaveDC(); pDC->SetBkColor(0); pDC->SetTextColor(m_FontColor); pDC->SelectObject(&m_Font); pDC->DrawText(m_szLabel,&rc,DT_VCENTER|DT_SINGLELINE); pDC->RestoreDC(iDC); delete pDC return TRUE; }

            L Offline
            L Offline
            Lizp
            wrote on last edited by
            #5

            It's get work, thank you ! Scratch

            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