Discussion:
GDIPlus WM_PAINT problem when another window moves over it
(too old to reply)
R.Wieser
2022-01-21 10:50:43 UTC
Permalink
Hello all,

I'm using GDIPlus to display an image in a controls WM_PAINT event
(BeginPaint, GdipCreateFromHDC, GdipDraw, GdipDeleteGraphics, EndPaint).
This works.

The problem occurs when I move another window over the control : I get a
mish-mash of the origional image interleaved with gray areas following
moved-over window.

Although I've found some ham-fisted solution by calling 'InvalidateRect'
just before 'BeginPaint' (causing a second paint event which covers op the
gray areas) I would like to know what correct way is to handle the problem.

Remark: I'm using the "flat api" set of GDI+ functions - on XPsp3.

Regards,
Rudy Wieser
Christian Astor
2022-01-30 09:54:41 UTC
Permalink
Post by R.Wieser
Hello all,
I'm using GDIPlus to display an image in a controls WM_PAINT event
(BeginPaint, GdipCreateFromHDC, GdipDraw, GdipDeleteGraphics, EndPaint).
This works.
The problem occurs when I move another window over the control : I get a
mish-mash of the origional image interleaved with gray areas following
moved-over window.
Although I've found some ham-fisted solution by calling 'InvalidateRect'
just before 'BeginPaint' (causing a second paint event which covers op the
gray areas) I would like to know what correct way is to handle the problem.
Remark: I'm using the "flat api" set of GDI+ functions - on XPsp3.
It works fine for me (Windows 10) :

Loading Image...

Global variable :

GpImage* img;

Main window :

//...
static hWndStatic = NULL;
//...

case WM_CREATE:
{
hWndStatic = CreateWindowEx(0, TEXT("Static"), TEXT(""), WS_CHILD |
WS_VISIBLE | SS_BITMAP, 10, 10, 500, 500, hWnd, (HMENU)IDC_STATIC,
hInst, NULL);
//hWndButton = CreateWindowEx(0, L"Button", L"Click", WS_CHILD |
WS_VISIBLE | BS_PUSHLIKE, 100, 60, 60, 32, hWnd, (HMENU)IDC_BUTTON,
hInst, NULL);

GpStatus nStatus = GdipLoadImageFromFile(L"E:\\Hulk.png", &img);
BOOL bRet = SetWindowSubclass(hWndStatic, StaticSubclassProc, 0, 0);
return 0;
}
break;


Subclass proc for Static to display image :


LRESULT CALLBACK StaticSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
switch (uMsg)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hDC = BeginPaint(hWnd, &ps);
GpGraphics *g;
GdipCreateFromHDC(hDC, &g);
GdipDrawImage(g, img, 0, 0);
GdipDeleteGraphics(g);
EndPaint(hWnd, &ps);
}
break;
}
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
Christian Astor
2022-01-30 10:01:05 UTC
Permalink
Post by Christian Astor
//...
static hWndStatic = NULL;
It is (in LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM
wParam, LPARAM lParam)):

static HWND hWndStatic = NULL;

and at beginning :

#define IDC_STATIC 10
R.Wieser
2022-01-30 11:22:55 UTC
Permalink
Christian,
Post by Christian Astor
HDC hDC = BeginPaint(hWnd, &ps);
GpGraphics *g;
GdipCreateFromHDC(hDC, &g); GdipDrawImage(g, img, 0, 0);
GdipDeleteGraphics(g);
EndPaint(hWnd, &ps);
Thats pretty-much the code I'm using. I've got no idea why your code
doesn't get the artifacts though.

Extra info: The image I'm drawing is big and scaled back to fit the control,
causing it to take a few tenths of a second to appear - which also causes a
lot of flickering when the control is resized. (solved that by disabeling
the WM_ERASEBKGND event and after the image is drawn fill out the remainder
of the control using a few rectangles).

I've got the feeling that the delay in the paint events image drawing causes
my problem. I've still got no idea how to handle that though ...

Just thought of something: Could you add a Sleep (of 50... 100 ms) just
before calling GdipDrawImage and see if that changes anything for you ?
Its not anything that will lead to a solution, but it would hammer down the
cause.

Regards,
Rudy Wieser
Christian Astor
2022-01-31 09:35:09 UTC
Permalink
Post by R.Wieser
Just thought of something: Could you add a Sleep (of 50... 100 ms) just
before calling GdipDrawImage and see if that changes anything for you ?
Its not anything that will lead to a solution, but it would hammer down the
cause.
Adding
Sleep(100);
doesn't change anything (just noticeable when the control is partially
out of the screen)
R.Wieser
2022-01-31 10:32:15 UTC
Permalink
Christian,
Post by R.Wieser
Just thought of something: Could you add a Sleep (of 50... 100 ms) just
before calling GdipDrawImage and see if that changes anything for you ?
Adding Sleep(100);
doesn't change anything (just noticeable when the control is partially out
of the screen)
Alas. Thanks for trying though.

Regards,
Rudy Wieser

Loading...