创建WIN32应用程序(面向对象)(C ++)

时间:2014-08-05 11:20:10

标签: c++ oop winapi

我似乎无法弄清楚这里有什么问题。该错误在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

enter image description here

以下是我所指的链接:http://www.functionx.com/win32/Lesson06.htm

1 个答案:

答案 0 :(得分:3)

您的问题是您将HINSTANCE, LPCTSTR, WNDPROC传递给Game构造函数。但它期望HINSTANCE, char *, WNDPROC。 T LPCTSTRchar*不同。

只需将Game构造函数的签名更改为Game(HINSTANCE, LPCTSTR, WNDPROC)