vc窗口程序问题 怎么才能看到窗口啊!!!1

#include <windows.h>int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst, LPSTR lpszCmdLine,int nCmdShow){ HWND hwnd; MSG Msg; WNDCLASS wndclass; char lpszClassName[]="窗口"; char lpszTitle[]="My_Windows";//窗口类的定义 wndclass.style=0; wndclass.lpfnWndProc=WndProc; wndclass.cbClsExtra=0; wndclass.cbWndExtra=0; wndclass.hInstance=hInstance; wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION); wndclass.hCursor=LoadCursor(NULL,IDC_ARROW); wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName=NULL; wndclass.lpszClassName=lpszClassName;//以下进行窗口类的注册 if(!RegisterClass(&wndclass)) { MessageBeep(0); return FALSE; }//创建窗口 hwnd=CreateWindow( lpszClassName, lpszTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while(GetMessage(&Msg,NULL,0,0)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam;}//窗口函数LRESULT CALLBACK WndProc(HWND hwnd, UINT message,WPARAM wParam,LPARAM lParam){ switch(message) { case WM_DESTROY: PostQuitMessage(0); default: return DefWindowProc(hwnd,message,wParam,lParam); } return (0);}--------------------Configuration: w1 - Win32 Debug--------------------Compiling...1.cppC:尀Program Files尀Microsoft Visual Studio尀MyProjects尀w1尀1.cpp(12) : error C2065: ✀WndProc✀ : undeclared identifierC:尀Program Files尀Microsoft Visual Studio尀MyProjects尀w1尀1.cpp(12) : error C2440: ✀=✀ : cannot convert from ✀int✀ to ✀long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)✀ Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style castC:尀Program Files尀Microsoft Visual Studio尀MyProjects尀w1尀1.cpp(53) : error C2373: ✀WndProc✀ : redefinition; different type modifiersError executing cl.exe.1.obj - 3 error(s), 0 warning(s)这个是错误!
2026年09月28日 22:03
有1个网友回答
网友(1):

WndProc函数没有进行声明,在WinMain前添加声明就行了。
形式如下:
LRESULT CALLBACK WndProc(HWND hwnd, UINT message,WPARAM wParam,LPARAM lParam);