我似乎无法弄清楚这里有什么问题。该错误在hInstance
#include "Game.h"
#include "WindowApp.h"
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT Msg,WPARAM wParam, LPARAM lParam);
//---------------------------------------------------------------------------
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg;
LPCTSTR ClsName = "Win32OOP";
LPCTSTR WndName = "Object-Oriented Win32 Programming";
// Initialize the application class
Game WinApp(hInstance, ClsName, MainWndProc); // Error here. Screenshot below
WinApp.RegWndClass();
// Create the main window
WindowApp Wnd;
Wnd.Create(hInstance, ClsName, WndName);
Wnd.Show();
// Process the main window's messages
while (GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return 0;
}
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT Msg,WPARAM wParam, LPARAM lParam)
{
switch (Msg)
{
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
return 0;
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
这是Game.h
#ifndef GAME_H
#define GAME_H
#define Win32_LEAN_AND_MEAN
// Include the basic windows header file
#include <Windows.h>
#include <windowsx.h>
class Game
{
// Global variable that holds the application
WNDCLASSEX _WndClsEx;
public:
Game();
// This constructor will initialize the application
Game(HINSTANCE hInst, char *ClasName,WNDPROC WndPrc, LPCTSTR MenuName = NULL);
// Class Registration
void RegWndClass();
~Game();
};
#endif
答案 0 :(得分:3)
您的问题是您将HINSTANCE, LPCTSTR, WNDPROC
传递给Game
构造函数。但它期望HINSTANCE, char *, WNDPROC
。 T LPCTSTR
与char*
不同。
只需将Game
构造函数的签名更改为Game(HINSTANCE, LPCTSTR, WNDPROC)
。