Click here to Skip to main content
15,881,812 members

how to draw continuous bitmap by using memory dc whithout memory leak and no response

April2004 asked:

Open original thread
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.
Tags: C++, MFC

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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