(帮助)功能错误' WinMain'在Eclipse CDT中

时间:2015-05-30 04:54:13

标签: c++ eclipse winapi

我正在尝试使用Eclipse CDT(在C ++中使用Eclipse)编写一个简单的Win32 GUI应用程序,但它会抛出一个错误:

  

C函数的冲突声明' int WinMain(HINSTANCE,int,LPSTR,int)

我的代码:

#include <windows.h>

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

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

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) {
    WNDCLASSEX cWindow;
    HWND hWnd;
    MSG Msg;

    cWindow.cbSize = sizeof(WNDCLASSEX);
    cWindow.lpszClassName = "cls";
    cWindow.lpfnWndProc = WndProc;
    cWindow.lpszMenuName = NULL;
    cWindow.hInstance = hInstance;
    cWindow.style = CS_OWNDC;
    cWindow.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    cWindow.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    cWindow.hCursor = LoadCursor(NULL, IDC_ARROW);
    cWindow.hbrBackground = (HBRUSH)3;
    cWindow.cbClsExtra = 0;
    cWindow.cbWndExtra = 0;

    if(!RegisterClassEx(&cWindow))
        MessageBox(NULL, "Error registring window class!", "Fatal error", MB_OK | MB_ICONERROR);

    hWnd = CreateWindowEx(0, "cls", "Title", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT,
                          640, 640, HWND_DESKTOP, NULL, hInstance, NULL);

    while(GetMessage(&Msg, NULL, NULL, NULL)) {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    DestroyWindow(hWnd);
    return 0;
}

它使用的是C ++语言,我使用的是MinGW编译器

0 个答案:

没有答案