我的C ++窗口出错

时间:2016-03-19 23:48:47

标签: c++ visual-studio-2015 window

是的,最近我一直在学习c ++,因为我想制作游戏。所以我做了什么,我开始制作一个c ++窗口但是在制作它的最后我想出了一个我无法解决的问题。在它所说的行wc.lpszClassName = L" ZakariyaTV'&#34 ;;我在等于下方得到一条红线。我花了太多时间试图解决它,但我不能。如果你知道如何解决它,真的很感激。谢谢。

这是我的代码:

#include<Windows.h>

HWND windowHandle;

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
    case WM_CLOSE:
        DestroyWindow(hwnd);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE preInstance, PSTR cmdLine, int showCmd)
{
    // Step 1

    WNDCLASSEX wc;

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hIconSm = 0;

    wc.hInstance = hInstance;
    wc.lpfnWndProc = WndProc;
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpszClassName = L"ZakariyaTV's Class";
    wc.lpszMenuName = 0;
    wc.hCursor = LoadCursor(0, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);

    // Step 2 
    RegisterClassEx(&wc);

    // Step 3
    windowHandle = CreateWindowEx(WS_EX_ACCEPTFILES, L"ZakariyaTV's Class", L"Game!",
        WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 800, 600, 0, 0, hInstance, 0);

    // Step 4 

    if (windowHandle == 0)
        MessageBoxA(0, "Create window failed", "Error Message", 0);

    // Step 5 

    ShowWindow(windowHandle, showCmd);

    // Step 6

    UpdateWindow(windowHandle);

    MSG msg;

    SecureZeroMemory(&msg, sizeof(MSG));
    int returnValue = 0;

    while ((returnValue = GetMessage(&msg, 0, 0, 0)) != 0)
    {
        if (returnValue == -1)
        {
            MessageBoxA(windowHandle, "GetMessage Failed!", "Error Message", 0);
            break;
        }

        TranslateMessage(&msg);
        DispatchMessage(&msg);


    }
    return (int)msg.wParam;
}

1 个答案:

答案 0 :(得分:0)

Visual Studio 2015在创建新项目时默认使用多字节字符集,但L&#34; ZakariyaTV&#39;&#34;告诉编译器该字符串应该编译为Unicode,因此您应该更改项目的字符集:在VS 2015中右键单击项目,然后在Project Defaults下选择Properties-&gt; General-&gt; Character set,最后更改您的之前的&#34;使用多字节字符集&#34; to&#34;使用Unicode字符集&#34;。