我编写了一个窗口程序,一开始运行成功了,后来我又在里面加了一个单击鼠标右键的窗口过程函数,结果调试时报告了错误观点1,我把后来加的函数注释后再次调试又报告了错误2.我不明白是怎么回事,请高手指教.谢谢!以下是我编写的代码和报告的错误.
//以下是LDS编写的代码,窗口程序已调试成功
#include //头文件
#include
LRESULT CALLBACK WinSunProc( //声明窗口过程函数
HWND hwnd, // handle to window 窗口句柄
UINT uMsg, // message identifier 消息代码
WPARAM wParam, // first message parameter 消息的附加参数
LPARAM lParam // second message parameter
);
int WINAPI WinMain( //主函数说明
HINSTANCE hInstance, // handle to current instance 当前运行的实例句柄
HINSTANCE hPrevInstance, // handle to previous instance 当前实例的前一个实例的句柄
LPSTR lpCmdLine, // command line 指向应用程序的命令行参数的指针
int nCmdShow // show state 指定窗口如何显示
)
{
WNDCLASS wndcls; //定义一个窗口类
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_ARROW);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
//wndcls.hIcon=LoadIcon(hinstance,"IDI_MYICON");
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="LDS2007";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("LDS2007","LDS开发的窗口软件",WS_OVERLAPPEDWINDOW,
0,0,1000,600,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char code is %d",wParam);
MessageBox(hwnd,szChar,"char",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"单击了鼠标左键","消息框",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,80,"LDS编写的第一个窗口程序",strlen("LDS编写的第一个窗口程序"));
TextOut(hdc,0,50,"这是单击鼠标左键形成的消息反应",strlen("这是单击鼠标左键形成的消息反应"));
ReleaseDC(hwnd,hdc);
break;
//自此以下的标号1-8行是后来加的
case WM_RBUTTONDOWN: //1
MessageBox(hwnd,"单击了鼠标右键","MessageBox消息框",0);
HDC hDC;
hdc=GetDC(hwnd);
TextOut(hdc,0,120,"这是单击鼠标右键形成的消息反应",strlen("这是单击鼠标右键形成的消息反应"));
ReleaseDC(hwnd,hdc);
break; //8
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,20,"LXGAJLDPCSLDS",strlen("LXGAJLDPCSLDS "));
TextOut(hDC,0,0,"LDS编写的程序这是窗口重绘形成的消息反应",strlen("LDS编写的程序这是窗口重绘形成的消息反应"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束此程序?","消息框message",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
以下是报告的两次错误:
--------------------Configuration: FLDS - Win32 Debug--------------------//错误1
Compiling...
FLDS.CPP
d:\学习作业\flds\flds.cpp(179) : error C2086: 'hDC' : redefinition
Error executing cl.exe.
FLDS.exe - 1 error(s), 0 warning(s)
-------------------Configuration: LDS_3 - Win32 Debug--------------------//错误2
Linking...
LINK : fatal error LNK1168: cannot open Debug/LDS_3.exe for writing
Error executing link.exe.
LDS_3.exe - 1 error(s), 0 warning(s)
--------------------next---------------------
阅读(1020) | 评论(0) | 转发(0) |