关于windows编程的问题 100
源程序:#include"windows.h"#include"stdio.h"LRESULTCALLBACKWinSunProc(HWNDhwnd,UINTuMsg,L...
源程序:
#include "windows.h"
#include "stdio.h"
LRESULT CALLBACK WinSunProc(HWND hwnd,UINT uMsg,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
WNDCLASS wndcls;
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 0;
wndcls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndcls.hCursor = LoadCursor(NULL, IDC_CROSS);
wndcls.hInstance = hInstance;
wndcls.lpfnWndProc = WinSunProc;
wndcls.lpszClassName = "Visual C++ Game";
wndcls.lpszMenuName = NULL;
wndcls.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd = CreateWindow("Visual C++ Game","Visual C++ 游戏开发",WS_OVERLAPPEDWINDOW,200,200,600,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd, SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch (uMsg)
{
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint(hwnd, &ps);
TextOut(hDC, 200, 0, "Visual C++ 游戏开发", strlen("Visual C++ 游戏开发"));
EndPaint(hwnd, &ps);
break;
case WM_CLOSE:
if (IDYES == MessageBox(hwnd, "是否真的结束?", "游戏开发", MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY :
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
return 0;
}
}
用的是VS2013,报错语句是wndcls.lpfnWndProc = WinSunProc;
错误 1 error C2440: “=”: 无法从“LRESULT (__stdcall *)(HWND,UINT,LPARAM)”转换为“WNDPROC” e:\vs2013 程序\winc++\winc++\源代码01.cpp 14 1 WinC++
求解 展开
#include "windows.h"
#include "stdio.h"
LRESULT CALLBACK WinSunProc(HWND hwnd,UINT uMsg,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
WNDCLASS wndcls;
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 0;
wndcls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndcls.hCursor = LoadCursor(NULL, IDC_CROSS);
wndcls.hInstance = hInstance;
wndcls.lpfnWndProc = WinSunProc;
wndcls.lpszClassName = "Visual C++ Game";
wndcls.lpszMenuName = NULL;
wndcls.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd = CreateWindow("Visual C++ Game","Visual C++ 游戏开发",WS_OVERLAPPEDWINDOW,200,200,600,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd, SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch (uMsg)
{
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint(hwnd, &ps);
TextOut(hDC, 200, 0, "Visual C++ 游戏开发", strlen("Visual C++ 游戏开发"));
EndPaint(hwnd, &ps);
break;
case WM_CLOSE:
if (IDYES == MessageBox(hwnd, "是否真的结束?", "游戏开发", MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY :
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
return 0;
}
}
用的是VS2013,报错语句是wndcls.lpfnWndProc = WinSunProc;
错误 1 error C2440: “=”: 无法从“LRESULT (__stdcall *)(HWND,UINT,LPARAM)”转换为“WNDPROC” e:\vs2013 程序\winc++\winc++\源代码01.cpp 14 1 WinC++
求解 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询