Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC
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).
 
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
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 19-Apr-12 6:07am
Edited 19-Apr-12 6:51am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  

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

  Print Answers RSS
0 Schatak 400
1 OriginalGriff 355
2 Sergey Alexandrovich Kryukov 144
3 _Amy 115
4 Rob Philpott 100
0 OriginalGriff 7,097
1 Sergey Alexandrovich Kryukov 5,623
2 Maciej Los 3,504
3 Peter Leow 3,373
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 20 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100