Every once in a while you'll find that you need to lock the screen so that updates don't happen to it. For instance, let's say you're adding a whole bunch of data to the screen in one go, but you don't want to trigger a redraw each time you add an item. Instead, you want to redraw once all of the items are done being added.
Well, in the past I've advocated the use of LockWindowUpdate for this situation. However, I've recently learned the error of my ways -- this is not an appropriate use for that Win32 API. That API was originally intended for drag and drop operations on Windows 3.1 era machines. There are no legitimate uses for the API outside of drag and drop, and with "modern" versions of Windows (about 98 and up, I'd say) there's not a reason to use it ever. Using it can cause all sorts of strange things to happen.
Instead, you should be using the WM_SETREDRAW message to tell a particular window that it should or should not be redrawing. The basic idea is that you send a WM_SETREDRAW to the window and tell it to not redraw. Then you do your operations how you normally would. Then you send another WM_SETREDRAW message to the window telling it that redraws are fine again. Finally, you invalidate the window so that it can redraw itself.
The next version of the WFS will be yanking its calls to LockWindowUpdate and may possibly be replacing them with the proper call. I have to examine the ramifications first before I make a final decision though. But I figured you'd want to hear about it sooner rather than later, hence this retraction.
How do they work differently? Does the new(er) API allow some changes from the OS so the window isn't completely locked, or something?
LockWindowUpdate works on a revolving-door sort of basis. You can only have one locked window at a time. This causes problems when you have several windows trying to vie for LockWindowUpdate. If Window A locks, then Window B locks, what happens? What's more, if Window B unlocks, what happens? In the case of LockWindowUpdate, the answer is "bad things."
The WM_SETREDRAW message (which has been around for a long, long time I might add) doesn't have this problem as it's on a window-by-window basis. So Window A and Window B can both not be redrawing and life is fine.
ah. Makes sense. Thanks Aaron!
I just read an article from Verity Stob that was (also) mislead by the MSDN docs for the LockWindowUpdate API:
http://www.regdeveloper.co.uk/2007/03/08/msdn_gloom/