我是一名刚学习VC++的新手,请大大们指点一二,万分感谢

洛丹伦之心 2009-05-04 11:20:05
这是我照着书打的一个现实鼠标实时位置的程序,结果无论如何都出问题,我附了代码和编译报告,请指点一二,谢谢
#include "stdafx.h"

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
MyRegisterClass(hInstance);
if(!InitInstance(hInstance,nCmdShow))
{return FALSE;
}
while(GetMessage(&msg,NULL,0,0))
{TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam ;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize =sizeof(WNDCLASSEX);
wcex.style =CS_HREDRAW |CS_VREDRAW;
wcex.lpfnWndProc =(WNDPROC)WndProc;
wcex.cbClsExtra =0;
wcex.cbWndExtra =0;
wcex.hInstance =hInstance;
wcex.hIcon =LoadIcon(hInstance,(LPCTSTR)IDI_MOUSEMOVE);
wcex.hCursor =LoadCursor(NULL,IDC_ARROW);
wcex.hbrBackground =(HBRUSH)(COLOR_WINDOW+1);
...全文
102 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dskit 2009-05-05
  • 打赏
  • 举报
回复
代码和编译报告???where?
洛丹伦之心 2009-05-05
  • 打赏
  • 举报
回复
不好意思,第一次发帖,昨天打漏了,代码和编译都在下面
#include "stdafx.h"

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
MyRegisterClass(hInstance);
if(!InitInstance(hInstance,nCmdShow))
{return FALSE;
}
while(GetMessage(&msg,NULL,0,0))
{TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam ;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize =sizeof(WNDCLASSEX);
wcex.style =CS_HREDRAW |CS_VREDRAW;
wcex.lpfnWndProc =(WNDPROC)WndProc;
wcex.cbClsExtra =0;
wcex.cbWndExtra =0;
wcex.hInstance =hInstance;
wcex.hIcon =LoadIcon(hInstance,(LPCTSTR)IDI_MOUSEMOVE);
wcex.hCursor =LoadCursor(NULL,IDC_ARROW);
wcex.hbrBackground =(HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName =NULL;
wcex.lpszClassName="Mousemove";
wcex.hIconSm=LoadIcon(wcex.hInstance,(LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
BOOL InitInstance(HINSTANCE hInstance,int nCmdShow)
{
HWND hWnd;
hInst=hInstance;
hWnd=CreateWindow("Mousemove","实时鼠标坐标显示",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,0,CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);
if(!hWnd)
{return FALSE;
}
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
POINT pt;
CHAR szString[255];
switch(message)
{
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
EndPaint(hWnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_MOUSEMOVE:
pt.x=LOWORD(lParam);
pt.y=HIWORD(lParam);
sprintf( szString,"[ %d, %d] ",pt.x,pt.y);
hdc=GetDC(hWnd);
TextOut(hdc,300,200,szString,strlen(szString));
ReleaseDC(hWnd,hdc);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}
Compiling...
xutao1.cpp
c:\program files\microsoft visual studio\myprojects\xutao1\xutao1.cpp(4) : warning C4652: compiler option 'Generate Browser Info' inconsistent with precompiled header; current command-line option will override that defined in the precompiled header
C:\Program Files\Microsoft Visual Studio\MyProjects\xutao1\xutao1.cpp(12) : error C2065: 'MyRegisterClass' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\xutao1\xutao1.cpp(13) : error C2065: 'InitInstance' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\xutao1\xutao1.cpp(23) : error C2373: 'MyRegisterClass' : redefinition; different type modifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\xutao1\xutao1.cpp(27) : error C2065: 'WndProc' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\xutao1\xutao1.cpp(31) : error C2065: 'IDI_MOUSEMOVE' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\xutao1\xutao1.cpp(36) : error C2065: 'IDI_SMALL' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\xutao1\xutao1.cpp(39) : error C2373: 'InitInstance' : redefinition; different type modifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\xutao1\xutao1.cpp(39) : error C2601: 'InitInstance' : local function definitions are illegal
C:\Program Files\Microsoft Visual Studio\MyProjects\xutao1\xutao1.cpp(51) : error C2373: 'WndProc' : redefinition; different type modifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\xutao1\xutao1.cpp(51) : error C2601: 'WndProc' : local function definitions are illegal
C:\Program Files\Microsoft Visual Studio\MyProjects\xutao1\xutao1.cpp(78) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

xutao1.exe - 11 error(s), 1 warning(s)

firsthym 2009-05-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 dskit 的回复:]
代码和编译报告???where?
[/Quote]
in his mind
lizhi110110110 2009-05-04
  • 打赏
  • 举报
回复
帮你顶一下啊 继续努力

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧