Continued from previous post ...
WinAPI - ExtTextOut (example 1 of 2)
This first example of the ExtTextOut API is similar to the
FlickerMin example in post 7 (see post 7 for the source.)
It demonstrates ExtTextOut's ability to clip text to a rectangle. It clears the background areas as necessary when processing the WM_PAINT message instead of letting the default window procedure clear it when processing the WM_ERASEBKGND. It produces less flicker than
FlickerMin because it uses a smaller font. (NOTE: the flicker is easier to see when resizing the window horizontally only.)
Also note that it does not specify CS_HREDRAW nor CS_VREDRAW in the class styles, instead it invalidates the client area, _without erasing it_ when processing the WM_SIZE message.
The rectangle coordinates used to erase the background can be output onto a console by recompiling the program with the "DEBUG" define active. This is useful to see/verify the coordinates of the background rectangles that are erased when painting.
Use the options under the "ExtTextOut" menu to control the clipping of text.
It also demonstrates how to process the WM_GETMINMAXINFO to control the minimum width and height of the window.
WinAPI - InvalidateRect Carefully controlling which parts of the client area are invalidated can significantly reduce flicker.
This example shows the effect of invalidating the entire client area compared to the effect of invalidating a smaller area that is the one that needs to be updated. When "Invalidate entire area" is selected in the "InvalidateRect" menu, the amount of flicker will be very noticeable. When "Invalidate coordinate area" is selected, the amount of flicker is drastically reduced and confined to a much smaller area.
The flicker left is due to the use of TextOut and specifying TRUE in the call to InvalidateRect when processing the WM_MOUSEMOVE message:
InvalidateRect(Wnd, @UpdateRect, TRUE);
This causes the coordinate area to be erased thus showing a clear background before TextOut outputs the new coordinate values.
NOTE: All the coordinates shown are relative to the _client area_ of the respective windows.
WinAPI - ExtTextOut (example 2 of 2)
This example is the InvalidateRect example but with all flicker removed. The absence of flicker is due to the different way the coordinate rectangle is invalidated when processing the WM_MOUSEMOVE message:
InvalidateRect(Wnd, @CoordinateRect, FALSE); { NO background erase! }
Note, that InvalidateRect is instructed not to require the background to be erased by specifying FALSE (third parameter.) This combined with the fact that ExtTextOut repaints the background and the text in one operation eliminates all flicker in the coordinates area.
However, it is still possible to see some occasional flicker when first pressing the left mouse button. The default processing of the WM_LBUTTONDOWN message Invalidates the entire client area with the statement:
InvalidateRect(Wnd, nil, TRUE);
This will cause some flicker to be noticeable if the left mouse button is very quickly pressed down and released (about 7 to 10 times per seconds) for a few seconds (5 seconds should normally enough.)
That occasional flicker can be removed by selecting "Exclude bottom line from invalidated area" which will cause the call to InvalidateRect to be:
MenuItemState := GetMenuState(GetMenu(Wnd), IDM_EXCLUDE, MF_BYCOMMAND);
case MenuItemState <> 0 of
true :
begin
{ menu item is checked, exclude the bottom of the client area }
GetClientRect(Wnd, ClientRect);
ClientRect.Bottom := ClientRect.Bottom - Exclude;
InvalidateRect(Wnd, @ClientRect, TRUE);
end;
thus excluding the area where the ExtTextOut definition is drawn causing all flicker to be eliminated.
NOTE: the ExtTextOut attachment contains both examples.
Continued on next post ...