#ifndef UNICODE
#define UNICODE
#endif

#include <windows.h>

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int     nCmdShow)
{

const wchar_t CLASS_NAME[]  = L"Sample Window Class";

WNDCLASS wc = { };

wc.lpfnWndProc   = WindowProc;
wc.hInstance     = hInstance;
wc.lpszClassName = CLASS_NAME;

RegisterClass(&wc);



HWND hwnd = CreateWindowEx(
    0,
    CLASS_NAME,
    L"Learn to Program Windows",
    WS_OVERLAPPEDWINDOW,


    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,

    NULL,
    NULL,
    hInstance,
    NULL
    );

if (hwnd == NULL)
{
    return 0;
}

ShowWindow(hwnd, nCmdShow);



MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0))
{
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}

return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_DESTROY:
    PostQuitMessage(0);
    return 0;

case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(hwnd, &ps);

        FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));

        EndPaint(hwnd, &ps);
    }
    return 0;

}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

这是代码,这也是您可以在Microsoft网站上找到的标准示例,该网站教人们如何对Windows进行编程。
http://msdn.microsoft.com/en-us/library/windows/desktop/ff381409(v=vs.85).aspx

每当我尝试在代码块中编译此代码时,都会收到以下问题。

未定义对“WinMain @ 16”的引用

那是什么,我该怎么做才能编译和运行这段代码?

最佳答案

对我来说,WinMain称为wWinMain似乎很奇怪:显然,您需要一个名为WinMain的函数。

哦,等等,您正在使用代码块? wWinMain可能是Visual Studio特有的。代码块需要标准的WinMain

关于c++ - 在Windows “undefined reference to ' WinMain @ 1 6'”中创建窗口时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16863194/

10-12 05:18