- difference between LockWindowUpdate () and WM_SETREDRAW?
- Posted by dan on December 26th, 2006
After I learned about WM_SETREDRAW in previous post today, I also found
lockwindowupdate fucntion. Can anybody explain difference between
lockwindowupdate () and WM_SETREDRAW? They are similar, based on what I
read in the documentation, and how they both worked with treeview. But
not identical, based on my test with a regular window:
LockWindowUpdate () displays as expected:
LockWindowUpdate (hwnd);
hdc = BeginPaint (hwnd, &ps);
// Painting operations
EndPaint (hwnd, &ps);
LockWindowUpdate (NULL);
WM_SETREDRAW (SetWindowRedraw) just ends up blank:
SetWindowRedraw (hwnd, FALSE);
hdc = BeginPaint (hwnd, &ps);
// Painting operations
EndPaint (hwnd, &ps);
SetWindowRedraw (hwnd, TRUE);
If I move SetWindowRedraw (hwnd, TRUE) inside BeginPaint / EndPaint
block, everything after SetWindowRedraw (hwnd, TRUE) is drawn. The
other changes are perhaps discarded. It seems to me the documentation
should explain the difference. Is LockWindowUpdate for regular
"windows", WM_SETREDRAW for listboxes and treeviews? Petzold, Simon,
and Newcomer books did not explain difference.
Thanks,
Daniel
- Posted by Sten Westerback \(MVP SDK\) on February 1st, 2007
"dan" <dagoldman@yahoo.com> wrote in message
news:1167099097.062383.146730@n51g2000cwc.googlegr oups.com...
As one is an API and the other an message the receiver can choose to ignore
the message but not the API (assuming it's not just a wrapper to a
SendMessage).
Anyway, your use of either is simply said flawed. BeginPaint is to be used
within a WM_PAINT and the purpose of either variant of the "lock" is to
cause the system not to send WM_PAINT message. So the call would be done
somewhere far from WM_PAINT. In your case the WM_SETREDRAW is like shooting
yourself if you foot - "i'm about to draw but.. nah... i want Windows to
lock my draw and record the invalidation until i have drawn and i unlock at
which stage i want it to, when system seems fit send me an appropriate
WM_PAINT... and so it would loop.. " 
- Sten
- Posted by Jeff Henkels on February 2nd, 2007
"Sten Westerback (MVP SDK)" <REMOVE_IF_NOSPAM_ext-sten.westerback@nokia.com>
wrote in message news:jbmwh.47351$Nb2.901105@news1.nokia.com...
To clarify a bit, is the API you're referring to SetWindowRedraw or
LockWindowUpdate? If the former, it is indeed a wrapper for
SendMessage(WM_SETREDRAW) -- see <windowsx.h>. If the latter,
take a look at
http://blogs.msdn.com/oldnewthing/ar...10/152612.aspx -- the
author says that LockWindowUpdate should be used only for drag/drop
feedback, as it is an exclusive lock (only one window can be locked at a
time).
- Posted by dan on February 3rd, 2007
On Feb 1, 5:46 am, "Sten Westerback \(MVP SDK\)" <REMOVE_IF_NOSPAM_ext-
sten.westerb...@nokia.com> wrote:
I admit I'm confused about WM_SETREDRAW and LockWindowUpdate. It seems
obvious the two capabilities are somewhat similar. But the SDK
documentation and the reference books were of little help in
clarifying the difference. Plus they had basically no examples. Plus
I'm not yet an expert win32 programmer.
Are you sure it's a bad idea to use WM_SETREDRAW or LockWindowUpdate
from within the response to WM_PAINT, before BeginPaint? I'm doing
this to prevent flicker when multiple items are being added to a tree
or listbox. It is working, but I don't feel comfortable using
something I don't understand.
I really appreciate getting these two responses at this late date. If
anyone has some skeletal examples, it would help. Or any other advice.
Daniel