Im trying to make a class for myself that will create a window.
So far I have:
(Header)
#include <windows.h>
class Win32Window
{
public:
void CreateWin32Window(HINSTANCE hInstance, int iWidth, int iHeight, int iShowCmd);
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
HWND WindowHandle;
};
(CPP)
#include "win32_window.h"
void Win32Window::CreateWin32Window(HINSTANCE hInstance, int iWidth, int iHeight, int iShowCmd)
{
WNDCLASS wcMain;
wcMain.style = CS_HREDRAW | CS_VREDRAW;
wcMain.cbClsExtra = 0;
wcMain.cbWndExtra = 0;
wcMain.lpszMenuName = 0;
wcMain.hCursor = ::LoadCursor(0, IDC_ARROW);
wcMain.hIcon = ::LoadIcon(0, IDI_APPLICATION);
wcMain.hbrBackground = (HBRUSH) ::GetStockObject(WHITE_BRUSH);
wcMain.hInstance = hInstance;
wcMain.lpfnWndProc = WndProc;
wcMain.lpszClassName = "My Window";
}
LRESULT CALLBACK Win32Window::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_LBUTTONDOWN:
::MessageBox(0, "Left Mouse", "", 0);
return 0;
case WM_KEYDOWN:
if(wParam == VK_ESCAPE)
{
::DestroyWindow(WindowHandle);
}
return 0;
case WM_DESTROY:
::PostQuitMessage(0);
return 0;
}
return ::DefWindowProc(hWnd, msg, wParam, lParam);
}
Its not finished yet but when trying to compile this code I get the error:
error C2440: '=' : cannot convert from 'LRESULT (__stdcall Win32Window::* )(HWND,UINT,WPARAM,LPARAM)' to 'WNDPROC'
How can I pass the window procedure of the class to the WNDCLASS strcuture?