B
Beach Potato
Hi:
I've searched newsgroups and various archives, including MSDN & MFC sources,
but at this point failed to locate an accurate and simple implementation of
WndProc function for MSWindows window objects.
Something like:
class BaseWindow {
virtual LRESULT WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam);
virtual OnPaint();
};
Then I would create a window pointing to a static StaticWndProc
static LRESULT CALLBACK StaticWndProc(HWND hwnd, UINT message, WPARAM
wParam, LPARAM lParam)
{
return DefWindowProc(hwnd, message, wParam, lParam);
}
But at certain point this static wndproc should be switched to the
BaseWindow::WndProc or gain access to the instance of the BaseWindow object
somehow. What is the simplest technique to make it happen?
So far, I figured only a way to throw an exclusive global pointer of this to
GWL_USERDATA and retrieve the object instance from it within every event
thrown to the static window procedure.
BaseWindow* g_window_ptr;
static LRESULT CALLBACK InitWndProc(HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
SetWindowLong( hWnd, GWL_USERDATA, (long) g_window_ptr );
SetWindowLong( hWnd, GWL_WNDPROC, (long) StaticWndProc__v2 );
return DefWindowProc(hwnd, message, wParam, lParam);
}
static LRESULT CALLBACK StaticWndProc__v2(HWND hwnd, UINT message, WPARAM
wParam, LPARAM lParam)
{
BaseWindow* l_window_ptr = (BaseWindow *) GetWindowLong( hWnd,
GWL_USERDATA );
return l_window_ptr->WndProc(hwnd, message, wParam, lParam);
}
What other simple ways do you use to build windows classes, inheriting
WndProc and event handlers?
I've searched newsgroups and various archives, including MSDN & MFC sources,
but at this point failed to locate an accurate and simple implementation of
WndProc function for MSWindows window objects.
Something like:
class BaseWindow {
virtual LRESULT WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam);
virtual OnPaint();
};
Then I would create a window pointing to a static StaticWndProc
static LRESULT CALLBACK StaticWndProc(HWND hwnd, UINT message, WPARAM
wParam, LPARAM lParam)
{
return DefWindowProc(hwnd, message, wParam, lParam);
}
But at certain point this static wndproc should be switched to the
BaseWindow::WndProc or gain access to the instance of the BaseWindow object
somehow. What is the simplest technique to make it happen?
So far, I figured only a way to throw an exclusive global pointer of this to
GWL_USERDATA and retrieve the object instance from it within every event
thrown to the static window procedure.
BaseWindow* g_window_ptr;
static LRESULT CALLBACK InitWndProc(HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
SetWindowLong( hWnd, GWL_USERDATA, (long) g_window_ptr );
SetWindowLong( hWnd, GWL_WNDPROC, (long) StaticWndProc__v2 );
return DefWindowProc(hwnd, message, wParam, lParam);
}
static LRESULT CALLBACK StaticWndProc__v2(HWND hwnd, UINT message, WPARAM
wParam, LPARAM lParam)
{
BaseWindow* l_window_ptr = (BaseWindow *) GetWindowLong( hWnd,
GWL_USERDATA );
return l_window_ptr->WndProc(hwnd, message, wParam, lParam);
}
What other simple ways do you use to build windows classes, inheriting
WndProc and event handlers?