From: k.sahici on
On Jun 12, 3:36 pm, "ScottMcP [MVP]" <scott...(a)mvps.org> wrote:
> > On 12-Jun-10 14:52, k.sahici wrote:
> > > I tried it but it didn't work. I still have to do something else for
> > > the control to be repainted, such as minimizing the dialog.
> > > Do you have any other idea?
>
> Are you testing with a debug build? That checks a lot of things for
> you. Did you change the ID of the control? (IDC_STATIC won't work.)
> Does the control have a DDX_Control call?  Can't guess very well if
> you don't show the code details.

Thank you for your reply, Scott.
Let me take it from the start. I changed the ID of the control from
IDC_STATIC to IDC_ITEM_IMAGE. In my dialog class I declared the
variable as
CPictureEx m_Loader;
I also added this DDX control call
DDX_Control(pDX, IDC_ITEM_IMAGE, m_Loader);

This CPictureEx class has a member function called Unload() to unload
the picture. I called this function but my dialog kept showing the old
image. When I minimized and maximized the dialog, the image
disappeared as it was expected to be. After that, I realized that I
had to force the dialog to repaint the control with the ID,
IDC_ITEM_IMAGE. However, the only solution that worked was to call
AfxGetMainWnd()->Invalidate(); which causes an annoying flickering
because it repaints the whole dialog.

To sum up, I think what I need is just to repaint a region of the
dialog. That's why I tried using various combinations of
InvalidateRgn, UpdateWindow, SetRedraw, etc. but none of them worked.

Kivanc
From: ScottMcP [MVP] on
On Jun 14, 1:29 am, "k.sahici" <k.sah...(a)gmail.com> wrote:
> To sum up, I think what I need is just to repaint a region of the
> dialog. That's why I tried using various combinations of
> InvalidateRgn, UpdateWindow, SetRedraw, etc. but none of them worked.
>
> Kivanc

m_Loader.Invalidate();

should cause the control to repaint. Repainting the dialog (or part
of it) is not the answer. The control must paint itself, the dialog
does not paint it. Maybe the control is poorly designed. Have you
tried a small test project that tests the control?
From: Preben Friis on
"ScottMcP [MVP]" <scottmcp(a)mvps.org> wrote in message
news:a6963a22-87ca-4bf8-9652-4bf74a7edd2a(a)d37g2000yqm.googlegroups.com...
> m_Loader.Invalidate();
> should cause the control to repaint.

I found the CPictureEx class, and determined that the code is indeed broken.
When it paints itself after UnLoad, it blits a NULL DC to the screen (which
does nothing).

Solution:

In "void CPictureEx::OnPaint()" Change:

::BitBlt(dc.m_hDC, 0, 0, m_PictureSize.cx, m_PictureSize.cy, m_hMemDC,
0, 0, SRCCOPY);

to

if (m_hMemDC)
{
::BitBlt(dc.m_hDC, 0, 0, m_PictureSize.cx, m_PictureSize.cy,
m_hMemDC, 0, 0, SRCCOPY);
}
else
{
CBrush brush(GetSysColor(COLOR_3DFACE));
CRect rect(CPoint(0, 0), GetSize());
dc.FillRect(rect, &brush);
}

... and then you can just call:

m_Picture.UnLoad();
m_Picture.Invalidate();

....in the dialog implementation.

/Preben Friis

From: k.sahici on
On Jun 14, 4:12 pm, "ScottMcP [MVP]" <scott...(a)mvps.org> wrote:
> On Jun 14, 1:29 am, "k.sahici" <k.sah...(a)gmail.com> wrote:
>
> > To sum up, I think what I need is just to repaint a region of the
> > dialog. That's why I tried using various combinations of
> > InvalidateRgn, UpdateWindow, SetRedraw, etc. but none of them worked.
>
> > Kivanc
>
> m_Loader.Invalidate();
>
> should cause the control to repaint.  Repainting the dialog (or part
> of it) is not the answer.  The control must paint itself, the dialog
> does not paint it.  Maybe the control is poorly designed.  Have you
> tried a small test project that tests the control?

I'm really confused. Assume that I had written a library to display
jpg files. What would I be supposed to do in order to remove the image
from the dialog? I really don't know much about diplaying image
files.

Even without calling Invalide() for m_Loader, repainting the dialog
(minimize plus maximize) removes the image. The only function that
needs to be called is the Unload function of this library. Might that
be a clue for this problem? Would you recommend using another library
in order to display image files on a simple, dialog based windows
application?
From: ScottMcP [MVP] on
On Jun 14, 2:50 pm, "k.sahici" <k.sah...(a)gmail.com> wrote:
> I'm really confused. Assume that I had written a library to display
> jpg files. What would I be supposed to do in order to remove the image
> from the dialog?  I really don't know much about diplaying image
> files.

The Unload function should call Invalidate, which causes WM_PAINT to
be generated. The control's WM_PAINT handler must paint something:
whatever should appear after the image is unloaded. Do you have the
source code for this control?