我有兩個類,Win32和引擎。我試圖將我的WindowProc函數從我的Engine類傳遞給Win32類。我知道的typedef WNDPROC聲明爲:將非靜態函數指針傳遞給另一個類?
typedef LRESULT(CALLBACK *WNDPROC)(HWND, UINT, WPARAM, LPARAM);
我的Win32頭被聲明爲:
// Win32.h
#include <Windows.h>
class Win32
{
public:
Win32() {};
~Win32() {};
void Initialize(WNDPROC);
private:
// Route messages to non static WindowProc that is declared in Engine class.
static LRESULT CALLBACK MessageRouter(HWND, UINT, WPARAM, LPARAM);
};
我的引擎類被聲明爲:
// Engine.h
#include "Win32.h"
class Engine
{
public:
Engine() {};
~Engine() {};
void Initialize();
private:
LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
Win32* m_win32;
};
// Engine.cpp
#include "Engine.h"
void Engine::Initialize()
{
m_win32 = new Win32;
m_win32->Initialize(&WindowProc); // How can I pass this function without making
// it static or global.
}
我的Win32類已經有一個給WNDCLASSEX的靜態MessageRouter。所以我的問題是,如何將Engine :: WindowProc函數傳遞給Win32類而不聲明它是靜態的還是全局的?
它有五個參數,'WNDPROC'有四個參數。你打算如何處理這個問題? – chris