C++ VS 2013错误C3861 Peek消息等和错误C2065 WNDCLASSEX

C++ VS 2013错误C3861 Peek消息等和错误C2065 WNDCLASSEX,c++,visual-studio-2013,compiler-errors,C++,Visual Studio 2013,Compiler Errors,我正在尝试一个新的用户图形教程,但我被卡住了。我是一个非常新的程序员…我的印象是,这些定义中的大部分都将包含在我的include中。我的消息处理程序缺少标识符“DefWindowProcess”,WINDCLASSEX也未被识别,GetModuleHandle函数,PeekMessage/TranslateMessage等。Microsoft开发中心说,所有这些定义都应该在windows.h中 #ifndef _SYSTEMCLASS_H_ #define _SYSTEMCLASS_H_ #d

我正在尝试一个新的用户图形教程,但我被卡住了。我是一个非常新的程序员…我的印象是,这些定义中的大部分都将包含在我的include中。我的消息处理程序缺少标识符“DefWindowProcess”,WINDCLASSEX也未被识别,GetModuleHandle函数,PeekMessage/TranslateMessage等。Microsoft开发中心说,所有这些定义都应该在windows.h中

#ifndef _SYSTEMCLASS_H_
#define _SYSTEMCLASS_H_

#define WIN32_LEAN_AND_MEAN

#include <windows.h>

#include "inputclass.h"
#include "graphicsclass.h"


class SystemClass
{
public:
SystemClass();
SystemClass(const SystemClass&);
~SystemClass();

bool Initialize();
void Shutdown();
void Run();

LRESULT CALLBACK MessageHandler(HWND, UINT, WPARAM, LPARAM);

private:
bool Frame();
void InitializeWindows(int&, int&);
void ShutdownWindows();

private:
LPCWSTR m_applicationName;
HINSTANCE m_hinstance;
HWND m_hwnd;

InputClass* m_Input;
GraphicsClass* m_Graphics;

};

static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

static SystemClass* ApplicationHandle = 0;

#endif

我发现,directx项目无法识别Windows API,我需要一个win32项目,在我的所有cpp文件上应用stdafx头文件,以使预编译头文件正常工作,并向所有头文件添加一次pragma以避免pch错误。事实证明,VS有点古怪。另外,对于所有其他noob,请确保为directx设置了文件路径,并通过project->add->newfile->适当的文件类型添加文件。这将使您不必担心知道正确的文件位置。

通常,您希望在预编译头中包含windows.h。您还可以复制/粘贴准确的错误消息,因为您的问题中有相当多的拼写错误。我建议将您的代码简化为一个简单的小示例,看看它是否有效,然后添加一些内容,看看它在哪里中断。你似乎有一个包含问题,但从你发布的代码中看不出它是什么。对不起,这也是我的第一篇文章。错误代码如下:错误C3861:“PeekMessage”:找不到标识符…除WNDCLASSEX外,其他所有标识符都相同,该WNDCLASSEX有错误C2065。因此,我需要对标题进行预编译,以使构建工作正常??您可以编辑问题以包含复制/粘贴错误。您永远不需要预编译头,但如果您使用的是预编译头,那么如果您做错了,它可能会把一些事情搞砸。没有看到更多的代码,任何人都只能猜测。
#include "pch.h"
#include "systemclass.h"

SystemClass::SystemClass()
{
m_Input = 0;
m_Graphics = 0;
}


bool SystemClass::Initialize()
{
int screenWidth, screenHeight;
bool result;

screenWidth = 0;
screenHeight = 0;

// Initialize the windows api.
InitializeWindows(screenWidth, screenHeight);

m_Input = new InputClass;
if (!m_Input)
{
    return false;
}

// Initialize the input object.
m_Input->Initialize();

// Create the graphics object.  This object will handle rendering all the graphics for this application.
m_Graphics = new GraphicsClass;
if (!m_Graphics)
{
    return false;
}

// Initialize the graphics object.
result = m_Graphics->Initialize(screenWidth, screenHeight, m_hwnd);
if (!result)
{
    return false;
}

return true;
}


void SystemClass::Shutdown()
{
// Release the graphics object.
if (m_Graphics)
{
    m_Graphics->Shutdown();
    delete m_Graphics;
    m_Graphics = 0;
}

// Release the input object.
if (m_Input)
{
    delete m_Input;
    m_Input = 0;
}

// Shutdown the window.
ShutdownWindows();

return;
}


void SystemClass::Run()
{
MSG msg;
bool done, result;


// Initialize the message structure.
ZeroMemory(&msg, sizeof(MSG));

// Loop until there is a quit message from the window or the user.
done = false;
while (!done)
{
    // Handle the windows messages.
    if ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    // If windows signals to end the application then exit out.
    if (msg.message == WM_QUIT)
    {
        done = true;
    }
    else
    {
        // Otherwise do the frame processing.
        result = Frame();
        if (!result)
        {
            done = true;
        }
    }

}

return;
}


bool SystemClass::Frame()
{
bool result;


// Check if the user pressed escape and wants to exit the application.
if (m_Input->IsKeyDown(VK_ESCAPE))
{
    return false;
}

// Do the frame processing for the graphics object.
result = m_Graphics->Frame();
if (!result)
{
    return false;
}

return true;
}


LRESULT CALLBACK SystemClass::MessageHandler(HWND hwnd, UINT umsg, WPARAM   wparam, LPARAM lparam)
{
switch (umsg)
{
    // Check if a key has been pressed on the keyboard.
case WM_KEYDOWN:
{

    m_Input->KeyDown((unsigned int)wparam);
    return 0;
}

// Check if a key has been released on the keyboard.
case WM_KEYUP:
{
    m_Input->KeyUp((unsigned int)wparam);
    return 0;
}

default:
{
    return DefWindowProc(hwnd, umsg, wparam, lparam);
}
}
}


void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight)
{
WNDCLASSEX wc; //THIS IS THE PROBLEM
DEVMODE dmScreenSettings;
int posX, posY;


// Get an external pointer to this object.  
ApplicationHandle = this;

// Get the instance of this application.
m_hinstance = GetModuleHandle(NULL);

// Give the application a name.
m_applicationName = L"Engine";

// Setup the windows class with default settings.
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = m_hinstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hIconSm = wc.hIcon;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = m_applicationName;
wc.cbSize = sizeof(WNDCLASSEX);

// Register the window class.
RegisterClassEx(&wc);

// Determine the resolution of the clients desktop screen.
screenWidth = GetSystemMetrics(SM_CXSCREEN);
screenHeight = GetSystemMetrics(SM_CYSCREEN);

    if (FULL_SCREEN)
{
            memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
    dmScreenSettings.dmSize = sizeof(dmScreenSettings);
    dmScreenSettings.dmPelsWidth = (unsigned long)screenWidth;
    dmScreenSettings.dmPelsHeight = (unsigned long)screenHeight;
    dmScreenSettings.dmBitsPerPel = 32;
    dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

    // Change the display settings to full screen.
    ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);

    // Set the position of the window to the top left corner.
    posX = posY = 0;
}
else
{
    // If windowed then set it to 800x600 resolution.
    screenWidth = 800;
    screenHeight = 600;

    // Place the window in the middle of the screen.
    posX = (GetSystemMetrics(SM_CXSCREEN) - screenWidth) / 2;
    posY = (GetSystemMetrics(SM_CYSCREEN) - screenHeight) / 2;
}

// Create the window with the screen settings and get the handle to it.
m_hwnd = CreateWindowEx(WS_EX_APPWINDOW, m_applicationName, m_applicationName,
    WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP,
    posX, posY, screenWidth, screenHeight, NULL, NULL, m_hinstance, NULL);

// Bring the window up on the screen and set it as main focus.
ShowWindow(m_hwnd, SW_SHOW);
SetForegroundWindow(m_hwnd);
SetFocus(m_hwnd);

// Hide the mouse cursor.
ShowCursor(false);

return;
}


void SystemClass::ShutdownWindows()
{
// Show the mouse cursor.
ShowCursor(true);

// Fix the display settings if leaving full screen mode.
if (FULL_SCREEN)
{
    ChangeDisplaySettings(NULL, 0);
}

// Remove the window.
DestroyWindow(m_hwnd);
m_hwnd = NULL;

// Remove the application instance.
UnregisterClass(m_applicationName, m_hinstance);
m_hinstance = NULL;

// Release the pointer to this class.
ApplicationHandle = NULL;

return;
}


LRESULT CALLBACK WndProc(HWND hwnd, UINT umessage, WPARAM wparam, LPARAM lparam)
{
switch (umessage)
{
    // Check if the window is being destroyed.
case WM_DESTROY:
{
    PostQuitMessage(0);
    return 0;
}

// Check if the window is being closed.
case WM_CLOSE:
{
    PostQuitMessage(0);
    return 0;
}

// All other messages pass to the message handler in the system class.
default:
{
    return ApplicationHandle->MessageHandler(hwnd, umessage, wparam, lparam);
}
}
}