Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

memory leakages

Status
Not open for further replies.

ceodav

Programmer
Feb 21, 2003
106
0
0
IT
Hi,
i have a little problem of memory leakages in my executable.
inside the function OnPaint() i send a user message (WM_REMOTETFT) to draw a bitmap upon the background image by means of BitBlt instruction.

here you can see a part of my code...

void CProva::OnPaint()
{
CClientDC dc(this);
PostMessage(WM_REMOTETFT);

}

void CProva::OnTFT(WPARAM wParam, LPARAM lParam)
{

CClientDC dc(this);
CDC dcTFT;
HDC hTFT;

HDC hDC=dc.m_hDC;

dcTFT.CreateCompatibleDC(&dc);

hTFT=dcTFT.m_hDC;

dcTFT.SelectObject(&picture);

CBitmap* pOldBitmap = dcTFT.SelectObject(&picture);
dc.BitBlt(X,Y,bmp.bmWidth, bmp.bmHeight, &dcTFT, 0,0,SRCCOPY);
dcTFT.SelectObject(pOldBitmap);

MSG msg;

while :):peekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{

::postQuitMessage(0);
break;
}

if (!AfxGetApp()->PreTranslateMessage(&msg))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
}
if :):IsWindow(m_hWnd))
{
PostMessage(WM_REMOTETFT);
}
::ReleaseDC((HWND)this, hDC);
::ReleaseDC((HWND)this, hTFT);

dcTFT.DeleteDC();
}

every time i change the focus (with alt+tab) from another program to mine and the message WM_PAINT is executed the size of my exe increase of 4K...
actually, i don't know the reason because i release all device context and all the CBitmap objects are initialized only in the constructor class

Anyone could suggest me a solution looking at the code?

thanks in advance
D.
 
Should you not be using CPaintDC in the OnPaint() handler?
 
if i use CPaintDC it's the same....

the problem is locatd in the OnTFT function because if i load only the baskground bitmap and i disabled the postmessage in the OnPaint it works good...

i really don't understand....



 
dcTFT.SelectObject(&picture);

CBitmap* pOldBitmap = dcTFT.SelectObject(&picture);


You don't actually have pOldBitmap since you didn't catch it in the first call.

-pete


 
Just a note on the coding: the OnPaint message doesn't need to declare CClientDC anyway since you're not using it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top