NO

Author Topic: ImgPreview  (Read 4854 times)

czerny

  • Guest
ImgPreview
« on: December 17, 2014, 05:47:04 PM »
I have attached a small project.

In the file 'ImgPrev.c' is a function named 'IPDrawItem()'.

I have long tried to get this example working using the second way in the #else part. I am shure, it should be possible not to delete the graphivs object. But I could not solve this problem. 'IPDrawItem' works then only in the first call, in the second I get a GpStatus == 1.

JohnF

  • Guest
Re: ImgPreview
« Reply #1 on: December 17, 2014, 06:00:58 PM »
When messing around with GDIPLUS I noticed that one had to delete the previous image before the new one could be accommodated.

John

czerny

  • Guest
Re: ImgPreview
« Reply #2 on: December 17, 2014, 06:29:52 PM »
When messing around with GDIPLUS I noticed that one had to delete the previous image before the new one could be accommodated.

I tried this:
Code: [Select]
void IPDrawItem(IP I, LPDRAWITEMSTRUCT dis)
{
RECT rect;
GpUnit  unit;
RectF src, dst;
    GpImage *image;

if (I && I->image && wcslen(I->fn))
{
#if 0
if (I->graphics)
GdipDeleteGraphics(I->graphics);
GdipCreateFromHDC(dis->hDC, &I->graphics);
#else
// shouldn't this work?
if (!I->graphics)
GdipCreateFromHDC(dis->hDC, &I->graphics);
#endif

GdipCloneImage(I->image, &image);
GetClientRect(dis->hwndItem, &rect);
dst.X = dst.Y = 0;
dst.Width = rect.right;
dst.Height = rect.bottom;

GdipGetImageBounds(image, &src, &unit);
GdiPlusDrawImageScaled(I->graphics, image, &dst, &src, UnitPixel, NULL);
GdipDisposeImage(image);
}
}

But the result is the same.

JohnF

  • Guest
Re: ImgPreview
« Reply #3 on: December 17, 2014, 07:20:18 PM »
I don't see what you are saying.

You still need to delete

GdipDeleteGraphics(I->graphics);

John

czerny

  • Guest
Re: ImgPreview
« Reply #4 on: December 17, 2014, 10:23:41 PM »
I don't see what you are saying.
I have deleted the image object in the last line. Haven't you said that I have to delete the image object?

laurro

  • Guest
Re: ImgPreview
« Reply #5 on: December 18, 2014, 12:29:34 AM »
czerny, when you build a graphics object you associate that graphics with one, single, particular hdc.
It is a parent/child relation, the hdc is the parent, and the graphics is the "smart" child. When the
parent (dis->hDC) go out of scope in the first WM_DRAWITEM, the child remains orphan and more importantly
he can play only in his parent house. The next WM_DRAWITEM: ( I assume you have WS_THICKFRAME for your
dialog ) the child is ok, alive, but the hdc (parent) is a totaly stranger. The child try to play in the
new house ( because you say so ), but, he doesn't recognise the new parent so he fail.
The solution: everytime the parent die, kill the children too,  everytime a new parent appear create a new child.

There is nothing wrong whith the Image, the code is a little redundant, no need for cloning the image.

Laur

czerny

  • Guest
Re: ImgPreview
« Reply #6 on: December 18, 2014, 08:54:14 AM »
laurro: So the short answer is, that my posted variant with the #if 1 section is right, isn't it?

laurro

  • Guest
Re: ImgPreview
« Reply #7 on: December 18, 2014, 09:50:11 AM »
very short...
Yes

Laur