Discussion:
Wait for paint event on MoveWindow?
(too old to reply)
Kevin Menard
2010-06-15 01:41:33 UTC
Permalink
Hi,

I'm trying to resize a window and then capture a screenshot of its contents.
To do so, I'm calling MoveWindow followed by PrintWindow. The problem is
PrintWindow is being triggered before the client area finishes repainting
from the move.

Is there any way to make the paint operation synchronous? Or is there some
other way to check that the client area has in fact repainted?

Thanks,
Kevin
Leo Davidson
2010-06-15 02:33:52 UTC
Permalink
Post by Kevin Menard
Is there any way to make the paint operation synchronous?
Call UpdateWindow.
Kevin Menard
2010-06-15 02:43:17 UTC
Permalink
On 6/14/10 10:33 PM, in article
Post by Leo Davidson
Post by Kevin Menard
Is there any way to make the paint operation synchronous?
Call UpdateWindow.
Thanks, I've tried that and I've tried calling InvalidateRect before
UpdateWindow. As I understand it, MoveWindow does this anyway. Still no
luck though.
--
Kevin
Leo Davidson
2010-06-15 08:20:55 UTC
Permalink
Post by Kevin Menard
Thanks, I've tried that and I've tried calling InvalidateRect before
UpdateWindow.  As I understand it, MoveWindow does this anyway.  Still no
luck though.
Yeah, if the last argument to MoveWindow is TRUE it should be like
calling UpdateWindow afterwards. From the docs it's not completely
clear if the entire client area is invalidated or just the parts which
are naturally invalidated (e.g. due to being obscured before the
move), but if you've tried "InvalidateRect(hwnd,NULL,TRUE);
UpdateWindow(hwnd);" then that'd definitely repaint the entire client
area.

(If you didn't try with InvalidateRect's bErase set to TRUE, give that
a go. Perhaps part of the window is painted in its WM_ERASEBKGND
handler? I'd expect MoveWindow to set the erase flag itself so it's
unlikely to make a difference but may be worth a quick try in the
absence of other ideas. :))

It might also be worth trying with WM_PRINT instead of PrintWindow.
Some windows/controls will look different when WM_PRINT is used but
some look the same.
Ken
2010-06-15 07:11:32 UTC
Permalink
void Move() {
HWND hwnd = FindWindow(L"Notepad", L"~~~.txt - Notepad");
MoveWindow(hwnd, 400, 0, 200, 200, FALSE);
PrintWindow(hwnd, ghdcMem, 0);
}

PrintWindow is triggered *after* the client area has finished repainting (auto line wrap)
from the MoveWindow(bRepaint = FALSE or TRUE).
Post by Kevin Menard
Hi,
I'm trying to resize a window and then capture a screenshot of its contents.
To do so, I'm calling MoveWindow followed by PrintWindow. The problem is
PrintWindow is being triggered before the client area finishes repainting
from the move.
Is there any way to make the paint operation synchronous? Or is there some
other way to check that the client area has in fac
Ken
2010-06-15 07:46:16 UTC
Permalink
Sorry!
In 50 testing
42 *after* client area repainting
5 *in* client area repainting (partial line)
3 *before* client area repainting (blank)
Post by Ken
void Move() {
HWND hwnd = FindWindow(L"Notepad", L"~~~.txt - Notepad");
MoveWindow(hwnd, 400, 0, 200, 200, FALSE);
PrintWindow(hwnd, ghdcMem, 0);
}
PrintWindow is triggered *after* the client area has finished repainting (auto line wrap)
from th
Ken
2010-06-15 12:14:35 UTC
Permalink
void Move() {
HWND hwnd = FindWindow(L"Notepad", L"~~~.txt - Notepad");
PrintWindow(hwnd, ghdcMem, 0);
}

Even without MoveWindow, In 50 testing
39 client area repainted fully
6 client area repainted partially
5 client area blank
Post by Ken
Sorry!
In 50 testing
42 *after* client area repainting
5 *in* client area repainting (partial line)
3 *before* client area repainting (blank)
Post by Ken
void Move() {
HWND hwnd = FindWindow(L"Notepad", L"~~~.txt - Notepad");
MoveWindow(hwnd, 400, 0, 200, 200, FALSE);
PrintWindow(hwnd, g
Leo Davidson
2010-06-15 08:23:54 UTC
Permalink
Post by Kevin Menard
I'm trying to resize a window and then capture a screenshot of its contents.
To do so, I'm calling MoveWindow followed by PrintWindow.  The problem is
PrintWindow is being triggered before the client area finishes repainting
from the move.
By the way, is this all being done on the UI thread which owns the
window, or are you calling Move/Update/PrintWindow across threads and/
or processes?
Kevin Menard
2010-08-01 13:59:03 UTC
Permalink
Hi Leo,

Thanks. I forgot to follow-up, but you were right. Apparently the thread I
was executing on was the same handling the main event processing loop, so my
code was preventing the actual redraw from occurring. Makes sense in
retrospect, but was pretty tricky to track down.
--
Kevin
Post by Leo Davidson
Post by Kevin Menard
I'm trying to resize a window and then capture a screenshot of its contents.
To do so, I'm calling MoveWindow followed by PrintWindow. The problem is
PrintWindow is being triggered before the client area finishes repainting
from the move.
By the way, is this all being done on the UI thread which owns the
window, or are you calling Move/Update/PrintWindow across threads and/
or processes?
.
Rene Pilon
2010-07-21 02:39:26 UTC
Permalink
Why not try to subslass the window and handle it all in WM_EXITSIZEMOVE?

Regards,

Rene Pilon
Post by Kevin Menard
Hi,
I'm trying to resize a window and then capture a screenshot of its contents.
To do so, I'm calling MoveWindow followed by PrintWindow. The problem is
PrintWindow is being triggered before the client area finishes repainting
from the move.
Is there any way to make the paint operation synchronous? Or is there some
other way to check that the client area has in fact repainted?
Thanks,
Kevin
Loading...