There is no easy solution to that one (if there were a general solution to a callback function that takes N arguments, I'd love to hear it).
You simply have to do what the link says. Blame C for that.
The reason is that the member functions are coupled to an instance. So if you pass a pointer to your member function, which instance of the function will it call?
Btw, I have also implemented a simple Window class. You may have a look at it and expand on it if you wish:
Code:
#ifndef WINDOWS_H_20100708_1707
#define WINDOWS_H_20100708_1707
#include <Windows.h>
#include "GetInstance.h"
#include <assert.h>
#include <boost/thread.hpp>
namespace Stuff
{
namespace Window
{
typedef LRESULT (CALLBACK WndProc_t)(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
class CWindow
{
protected:
HWND m_hWnd;
public:
// WndProc is a pointer to WndProc procedure. MUST call CWindow::WindowProc!
void Initialize(WndProc_t* WndProc)
{
// TODO: Place code here.
WNDCLASSEXW wcex = {};
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = Stuff::Handle::GetAppInstance();
wcex.hIcon = 0;
wcex.hCursor = 0;
wcex.hbrBackground = 0;
wcex.lpszMenuName = nullptr;
wcex.lpszClassName = L"Callback window";
wcex.hIconSm = 0;
assert(RegisterClassExW(&wcex));
// Perform application initialization:
m_hWnd = CreateWindowW(L"Callback window", L"", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, Stuff::Handle::GetAppInstance(), nullptr);
assert(m_hWnd);
// Main message loop:
boost::thread(&CWindow::MessageLoop, this);
}
protected:
void MessageLoop()
{
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
public:
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
~CWindow() { DestroyWindow(m_hWnd); }
HWND GetHwnd() { return m_hWnd; }
};
}
}
#endif