Why cannot I get a DC of a window in sometime after a longtime running
-
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
-
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
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; }
-
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; }
-
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
I think you simply need to do ReleaseDC( pDC ); "There's a slew of slip 'twixt cup and lip"
-
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; }