我正在浏览关于窗口创建的this教程,并且遇到了错误:
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);
}
答案 0 :(得分:0)
声明const wchar_t message
应替换为UINT
。由于参数错误而收到此错误。