Technical skill
George Frazier Editor
Translation: cwxiao888@163.com
Lock window update
Matthew Wilson Writing Matthew@synesis.com.au
One typical problem when updating the window during length and granular operation is that the window is flashing, changing the contents of the control results in a partial or all of the visible area of the control. This is a problem with a large number of updates in a short period of time, and this repeated heavy combination is in the form of visual interference without attractiveness. Two common ways to solve this problem are to use the API function LOCKWINDOWUPDATE and WM-SETREDRAW messages.
LockWindowUpdate is implemented by replacing the normal device scene of this window, replacing this window with an empty window in a visible area. When LockWindowUpdate is taken when a NULL call (unlocked window), the original device scene is replaced, the system invalidates the same area as the temporary window size and position within it, so that the window will receive a requirement Draw a modified area. So all windows are drawn in a single operation, and the visual effect is more seamless. The disadvantage of using LockWindowUpdate is that it can only be used in one window at a time, so it cannot be used to locate a group of related controls. Calling the first window of this function is locked, and all other calls before the lock is unlocked. (This is easily displayed, and the undesiiled artificial lock of the run button on the 93rd line of the test program is executed by the test program, Wndscope.cpp includes in this month's code document). Interestingly, using two versions of the application using LockWindowUpdate at the same time running, it looks, any process "has" the process "Have" lock function, removes the ownership of the previous successful call, which is restored to the flicker of the string Behavior insertion.
WM-SetredRaw is a message implemented by various standards and custom controls, including list boxes, Comboks (ComboBox), List View, Button, and TAB controls (Tab Control ). It works by clearance and setting window Heavy Picture (FLAG). The only minute disadvantage is that the application must fail after sending a recovery activity message, so all visual window rectangles will be redrawn. The use of WM-SetredRAW generally replaces the use of LockWindowUpdate. Of course, for windows that do not support this message, LockWindowUpdate is still optional.
Here, two classes in the Winstl library (http://winstl.org/) are given to Window_Redraw_scope-Provide two forms of automation of lock Locking. (Covered Implementation Some Contents See List 1 and List 2. The complete execution section is provided in the file file, and can be found in the Winstl site). Lock in the constructor constructor, then reset in the destructor:
window_update_scope its constructor call of LockWindowUpdate, if the call is successful in its destructor destructor LockWindowUpdate (NULL); window_redraw_scope transmitting WM-SETREDRAW in its constructor (transfer False) WM-SETREDRAW and transmits (transmission True). Both of them acquire the handle of the window to lock in their constructors; Window_redRaw_scope acquire the second parameter (default value true) to determine if the window is invalid (by call invalidate) if the window is not locked.