初学者的问题
小弟刚学vc有个程序调不过
#include <windows.h>
LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM);
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=LoadIcon(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
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: window - Win32 Debug--------------------
Compiling...
window.cpp
D:\vc\window.cpp(11) : error C2065: 'WndProc' : undeclared identifier
D:\vc\window.cpp(11) : 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 cast
D:\vc\window.cpp(34) : error C2373: 'WndProc' : redefinition; different type modifiers
Error executing cl.exe.
window.exe - 3 error(s), 0 warning(s)
请各位大虾指出错误原因,以便小弟改正。谢谢!
问题点数:100、回复次数:6Top
1 楼playboyxp(learning)回复于 2005-07-02 21:25:17 得分 0
自己顶Top
2 楼zhongjihang()回复于 2005-07-02 21:50:30 得分 15
不懂,帮你顶下Top
3 楼kylix2003(Jelly)回复于 2005-07-02 22:23:34 得分 15
我也不熟悉Windows编程,
帮你顶吧~Top
4 楼xing_xing_xing(哈哈)回复于 2005-07-02 22:41:47 得分 20
WndProc定义放到前面
#include <windows.h>
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;
}
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=LoadIcon(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
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;
}
Top
5 楼goodboyws(深夜不眠者(VCMVP))回复于 2005-07-02 22:55:22 得分 50
WinProc vs WndProc
呵呵Top
6 楼goodboyws(深夜不眠者(VCMVP))回复于 2005-07-02 22:56:43 得分 0
又是一个拼写错误Top




