class HookedWndProc
{
public:
HookedWndProc(HWND hWnd, WNDPROC WndProc);
~HookedWndProc();
private:
LRESULT CALLBACK m_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
// data
HWND m_hWnd;
WNDPROC m_WndProc;
WNDPROC m_prevWndProc;
};
HookedWndProc::HookedWndProc(HWND hWnd, WNDPROC WndProc)
{
m_hWnd = hWnd;
m_WndProc = WndProc;
m_prevWndProc = (WNDPROC)SetWindowLongA(m_hWnd, GWL_WNDPROC, /*error C2440: приведение типов*/ (LONG)m_WindowProc); // Ставим свой Window proc
}
HookedWndProc::~HookedWndProc()
{
SetWindowLongA(m_hWnd, GWL_WNDPROC, (LONG)m_prevWndProc); // Восстанавливаем прежний Window proc
}
LRESULT HookedWndProc::m_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) /* callback */
{
CallWindowProcA(this->m_WndProc, hWnd, uMsg, wParam, lParam); // Вызыв пользовательского Window proc
return CallWindowProcA(this->m_prevWndProc, hWnd, uMsg, wParam, lParam); // Вызов оригинального
}