Click to See Complete Forum and Search --> : Is this a bug in GDI+ or am i doing wrong


tmd
January 7th, 2007, 04:13 AM
I noticed my application doing this and so i used a stripped down deafult project to test it out with just a simple couple lines fo code in case WM_Paint and it is still doing it.

I make a call inside of WM_Paint to my function OnPaint(HDC hdc); which contains the simple code from MSDN of displaying a jpeg on the screen as follows:


Graphics graphics(hdc);

Image image(L"llama.jpg");
graphics.DrawImage(&image, 60, 10);



The problem is when i run the program and the window opens it displays the jpeg, but if i then move the window slightly, it redraws not only the jpeg where it should be but also a second version of the jepg behind it but offset to where it would have been if i hadnt moved the window a little bit.

attached is a picture of it so you can see what i mean:

Zaccheus
January 7th, 2007, 04:39 AM
It looks like you are not redrawing the white background around the image.

tmd
January 7th, 2007, 05:29 AM
Well the thing is when i move the window it redraws the jpeg fine as it should, and the white background is there as it should, but then after a 1 second delay or so the other picture shows up behind it. I tried this also with just drawing a line instead of an image nad theres no problem there so i dont think its a matter of redrawing th white background. The white background is part of the window attributes so windows should be taking care of that on its own.

ovidiucucu
January 8th, 2007, 11:29 AM
For sure there is not a bug in GDI+ but in your program.
Please, make a zip with your project and attach it here.
Then we can see what's wrong, else we cannot even guess.

// also, please do not open additonal threads with the same problem or with links to this one.

[ Redirected thread ]

tmd
January 8th, 2007, 04:13 PM
For sure there is not a bug in GDI+ but in your program.
Please, make a zip with your project and attach it here.
Then we can see what's wrong, else we cannot even guess.

// also, please do not open additonal threads with the same problem or with links to this one.

[ Redirected thread ]


Here are all the project files. Thanks

tmd
January 9th, 2007, 06:06 AM
After defragmenting my hard drive, it stopped doing it. Odd?

ovidiucucu
January 9th, 2007, 08:22 AM
After defragmenting my hard drive, it stopped doing it.
I'm wondering, for how long time... :D ;)

Well, now let's take a first look in your attached app.

First of all, note that your program usually will not work on other computer than yours because you haveused a lot of hard-coded paths and file names.
As for example
LPCTSTR path = L"C:\\Documents and Settings\\ac\\My Documents\\Visual Studio Projects\\Imagopher\\Debug\\Thumbs";
CreateDirectory(path, NULL);
CreateDirectory will usually fail on whatever computer becaue it does not create a full-path (will fail if C:\\Documents and Settings\\ac\\My Documents\\Visual Studio Projects\\Imagopher\\Debug\\ path does not exist).
If you are expecting, for example, to find the image files in the application directory, then you can get it like in this FAQ: How to get the application directory? (http://www.codeguru.com/forum/showthread.php?t=312471)

Alternatively, in a menu command handler (you already have ID_NEW_ALBUM32774 menu item which does nothing), you can find an existing directory (containing image files) like in GetFolder function from this Codeguru article: Shell Extension Folder Browser Function (http://www.codeguru.com/cpp/w-p/files/browserfunctionsdialogs/article.php/c4465/).
Note: it uses MFC, but it's not a big problem to adapt it by passing instead of CString* a C-style buffer pointer or an STL "string" pointer or reference.

Further, to get rid of hard-coded file names ("llama4.bmp", "llama3.JPG", and so on) you can search the directory using FindFirstFile/FindNextFile/FindClose.
Here there is also a FAQ that can help you: How to search for files in a directory... (http://www.codeguru.com/forum/showthread.php?t=312461)

Having these said, the real fact that leads you in troubles is that you have done "everything" in the WM_PAINT message handler. You have to separate other than paining stuff and put it separately in other place, e.g. in a menu command handler as suggested above. Note that loading from files, generating thumbnail images then save them in files are hard resources/time consuming and it's a very, very bad idea to put them in WM_PAINT which is for painting and only for the painting.

tmd
January 9th, 2007, 08:38 AM
Those are stub functions I am using to test out the image rendering functions. They will be implemeted with non hard coded paths. The app is in the very early stages. This is also why everything is in WM_PAINT. Eventually each thumbnail will be in its own little child window. The question, even though I appreciate the tips on the orginazation of the app, was plainly why the double rendering was taking place.