Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi Friends,
I face memory leak and no response when I try to paint continuous bitmap.
(Firstly, I would like to admit that I don't know complicated commands and I just able to use few commands. So, please don't be mind if my question is too simple.)
Here is the process that I try.

I would like to draw random color transparent pixel on fixed bitmap. I wrote the following code in MFC Dialog-based Application, OnPaint event. Then, I can see what I want(random color transparent pixel on fixed bitmap).

C++
CDC dc;
CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP_TESTBITMAP);
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);
CDC* pDC = this->GetDC();
dc.CreateCompatibleDC(pDC);
CBitmap* pOldBmp = dc.SelectObject(&bmp);
pDC->BitBlt(0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, &dc, 0, 0, SRCCOPY);

for (int i = 0; i < bmpInfo.bmHeight; i++) {
    for(int j = 0; j < bmpInfo.bmWidth; j++) {
	dc.SetPixel(j, i, RGB(rand()%100, rand()%50, rand()%100)); // ●●it is temporary test code (Actually, I will read file data in here)
    }
}
pDC->BitBlt(0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, &dc, 0, 0, SRCAND);
		
dc.SelectObject(pOldBmp);
bmp.DeleteObject();
dc.DeleteDC();
this->ReleaseDC(pDC);

CDialogEx::OnPaint();


In next step, I would like to set pixel from file data whenever the new file data is added to folder. So, I use
C++
do {
    ReadDirectoryChanges(...); // folder path and necessary parameters are passed
    pInfo = (FILE_NOTIFY_INFORMATION*) &buffer;
    If (pInfo->Action == FILE_ACTION_ADDED) {
         // ●●I will read file data and set pixel of file data here, the background IDB_BITMAP_TESTBITMAP is fixed as before.
    }

But the problem is after changing the program as above code and run it, just only the first file data is shown and no response after that. And also memory is occurred. What's big mistake with my code?
Thanks in advanced for your time and help.
Posted
Updated 19-Apr-12 6:51am
v2

1 solution

You need to trigger the drawing again, by calling CWNd::Invalidate() or better http://msdn.microsoft.com/en-US/library/2f3csed3(v=vs.80).aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900