Click here to Skip to main content
12,956,512 members (77,845 online)
Rate this:
Please Sign up or sign in to 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).

CDC dc;
CBitmap bmp;
BITMAP bmpInfo;
CDC* pDC = this->GetDC();
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);

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
Updated 19-Apr-12 6:51am
Jochen Arndt185.1K

1 solution

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

Solution 1

You need to trigger the drawing again, by calling CWNd::Invalidate() or better[^]

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,869
CHill60 3,550
Maciej Los 3,302
ppolymorphe 2,080
Jochen Arndt 1,973

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 20 Apr 2012
Copyright © CodeProject, 1999-2017
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