BazisLib::Win32::_DoubleBufferedControlHook<> Class Template Reference

Allows to turn standard GDI controls into double-buffered ones. More...

#include <dblbuf.h>

List of all members.

Public Member Functions

 _DoubleBufferedControlHook (HBRUSH hBackBrush)
 Creates the double-buffer hook control with a background brush.
 _DoubleBufferedControlHook (ULONG SystemColor=COLOR_BTNFACE)
 ~_DoubleBufferedControlHook ()
bool HookControl (HWND hWnd)
 Performs actual control hooking.

Static Private Member Functions

static LRESULT CALLBACK NewWindowProc (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
 Overrides the window proc for the hooked control.

Private Attributes

WNDPROC m_OldWindowProc
HBRUSH m_hBackBrush


Detailed Description

template<LRESULT(WINAPI *_CallWindowProc)(WNDPROC, HWND, UINT, WPARAM, LPARAM) = CallWindowProc>
class BazisLib::Win32::_DoubleBufferedControlHook<>

Allows to turn standard GDI controls into double-buffered ones.

This class allows using standard GDI controls, such as list views, in a double-buffered mode. That approach completely removes flickering on fast information update for these controls. You should never use the _DoubleBufferedControlHook directly. Instead use the DoubleBufferedControlHook or one of the specialized clases, such as DoubleBufferedStaticText:

class WindowClass
{
...
	DoubleBufferedControlHook m_Hook;
...

	OnCreate(...) //Or OnInitDialog()
	{
		...
		m_Hook.HookControl(GetDlgItem(...));
		// ---OR---
		m_Hook.HookControl(m_hwndSomeControl);
	}

}
Parameters:
_CallWindowProc allows specifying user-defined function that calls the original window procedure, performing some additional filtering, if required. By default, this parameter is set to CallWindowProc function provided by Windows. See the DoubleBufferedStaticText implementation for usage example
Attention:
The _DoubleBufferedControlHook class introduces several restrictions to the hooked window:
  • The GWL_USERDATA is managed by the _DoubleBufferedControlHook class and should not be changed by any other facility.
  • The hooked window should have the WM_PRINT message support. Most of the standard GDI controls support it (even under Windows CE where it is simply mapped to WM_PAINT with HDC in wParam). However, hooking user-provided controls may produce no result, as their window procedures may be unaware of this message.
Remarks:
On Windows CE the STATIC control does not support WM_PRINT message, that way the DoubleBufferedControlHook will not work with it. You should use DoubleBufferedStaticText instead.

Constructor & Destructor Documentation

template<LRESULT(WINAPI *_CallWindowProc)(WNDPROC, HWND, UINT, WPARAM, LPARAM) = CallWindowProc>
BazisLib::Win32::_DoubleBufferedControlHook<>::_DoubleBufferedControlHook ( HBRUSH  hBackBrush  )  [inline]

Creates the double-buffer hook control with a background brush.

As we ignore the WM_ERASEBKGND message and do all the erasing inside WM_PAINT, the background color or brush should be known to our override class. Use either this constructor, or the constructor taking a system color reference to specify it.

template<LRESULT(WINAPI *_CallWindowProc)(WNDPROC, HWND, UINT, WPARAM, LPARAM) = CallWindowProc>
BazisLib::Win32::_DoubleBufferedControlHook<>::_DoubleBufferedControlHook ( ULONG  SystemColor = COLOR_BTNFACE  )  [inline]

template<LRESULT(WINAPI *_CallWindowProc)(WNDPROC, HWND, UINT, WPARAM, LPARAM) = CallWindowProc>
BazisLib::Win32::_DoubleBufferedControlHook<>::~_DoubleBufferedControlHook (  )  [inline]


Member Function Documentation

template<LRESULT(WINAPI *_CallWindowProc)(WNDPROC, HWND, UINT, WPARAM, LPARAM) = CallWindowProc>
bool BazisLib::Win32::_DoubleBufferedControlHook<>::HookControl ( HWND  hWnd  )  [inline]

Performs actual control hooking.

This method should be called after the control that is to be hooked was created.

Parameters:
hWnd Specifies the window handle for the control to hook.
Remarks:
The DoubleBufferedControlHook would most likely not work with user-provided controls, because they do not support WM_PRINT. See class description for details.

Here is the call graph for this function:

template<LRESULT(WINAPI *_CallWindowProc)(WNDPROC, HWND, UINT, WPARAM, LPARAM) = CallWindowProc>
static LRESULT CALLBACK BazisLib::Win32::_DoubleBufferedControlHook<>::NewWindowProc ( HWND  hWnd,
UINT  wMsg,
WPARAM  wParam,
LPARAM  lParam 
) [inline, static, private]

Overrides the window proc for the hooked control.

This static method is called each time a message is sent to the hooked control. It actually handles only two messages: WM_ERASEBKGND and WM_PAINT. All other messages are simply forwarded to the original message function. For the WM_ERASEBKGND no work is performed, and WM_PAINT handler creates a temporary bitmap, invokes the original window procedure with it, and then copies the bitmap to the original DC.

Remarks:
The present version creates the bitmap/memory DC pair on each WM_PAINT call. This may be slower than having a cached one, however, this does not use the memory for bitmap outside the WM_PAINT call.
Attention:
DO NOT use the GWL_USERDATA for a hooked control.


Member Data Documentation

template<LRESULT(WINAPI *_CallWindowProc)(WNDPROC, HWND, UINT, WPARAM, LPARAM) = CallWindowProc>
HBRUSH BazisLib::Win32::_DoubleBufferedControlHook<>::m_hBackBrush [private]

template<LRESULT(WINAPI *_CallWindowProc)(WNDPROC, HWND, UINT, WPARAM, LPARAM) = CallWindowProc>
WNDPROC BazisLib::Win32::_DoubleBufferedControlHook<>::m_OldWindowProc [private]


The documentation for this class was generated from the following file:
SourceForge.net Logo