0

错误:

我正在阅读有关创建窗口的教程,但遇到了错误:

Error 1 error C2440: '=' : cannot convert from 'LRESULT (__stdcall *)(HWND,const wchar_t,WPARAM,LPARAM)' to 'WNDPROC'

问题:

这里出了什么问题?本教程是过时的还是类似的东西?

代码:

该代码与本教程的代码相同或几乎相同。

#include "windows.h"
#include "windowsx.h"

LRESULT CALLBACK WindowProc(HWND hWnd,
                            const wchar_t message,
                            WPARAM wParam,
                            LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    //Handle for the window, filled by a function
    HWND hWnd;

    //This struct holds information for the window class
    WNDCLASSEX wc;

    //Clear out the window class 
    ZeroMemory(&wc, sizeof(WNDCLASSEX));

    //Fill struct with needed information
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = "Window Class";

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

    //Create the window to use as a handle
    hWnd = CreateWindowEx(  NULL,
                            "Window Class",
                            "Our first window",
                            WS_OVERLAPPEDWINDOW,
                            300,
                            300,
                            500,
                            400,
                            NULL,
                            NULL,
                            hInstance,
                            NULL);

    ShowWindow( hWnd,
                nCmdShow);

    MSG msg;

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

    return msg.wParam;
}

//Main message handler
static LRESULT CALLBACK WindowProc(HWND hWnd,
                            const wchar_t message,
                            WPARAM wParam,
                            LPARAM lParam)
{
    //Find the code to run for the message
    switch(message)
    {
    case WM_DESTROY:
        {
            //Close the app entirely
            PostQuitMessage(0);
            return 0;
        } break;
    }

    //Handle any messages the switch didn't
    return DefWindowProc (hWnd, message, wParam, lParam);
}
4

1 回答 1

0

声明const wchar_t message应替换为UINT. 由于参数错误而收到此错误。

于 2013-05-19T05:18:23.093 回答