qiboda
1/25/2017 - 2:46 PM

pass_function_in_the_class.cpp

// This is from the introduce to 3D game program with directx 11.

// The MainWndProc can't in the class.
// And the MsgProc function is in the class.
// But the MainWndProc need to call MsgProc.
// Also, D3DApp is a abstract class.

// This method is so good.
namespace
{
	D3DApp* gd3dApp = nullptr;
}

LRESULT CALLBACK
MainWndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	return gd3dApp->MsgProc( hwnd, msg, wParam, lParam );
}

D3DApp::D3DApp()
{
	gd3dApp = this;
}

LRESULT D3DApp::MsgProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) { /* some code */}

bool D3DApp::InitMainWindow()
{
	WNDCLASS wc;
	wc.lpfnWndProc = MainWndProc;
}