来个高手来帮帮我这菜鸟,一个简单的vc++编程问题
程序如下,是照着教程输的,先是直接生成了一个简单的Win32应用程序,再加入的代码,#include"stdafx.h"ATOMMyRegisterClass(HINST...
程序如下,是照着教程输的,先是直接生成了一个简单的Win32应用程序,再加入的代码,
#include "stdafx.h"
ATOM MyRegisterClass(HINSTANCE hInstance);
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
BOOL InitInstance(HINSTANCE hInstance,int nCmdShow);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
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_HREDRAM | 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.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);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}
结果编译出现了以下问题,
-------------------Configuration: 4 - Win32 Debug--------------------
Compiling...
4.cpp
H:\程序\4\4.cpp(35) : error C2065: 'CS_HREDRAM' : undeclared identifier
H:\程序\4\4.cpp(40) : error C2065: 'IDI_MOUSEMOVE' : undeclared identifier
H:\程序\4\4.cpp(44) : error C2065: 'IDI_SMALL' : undeclared identifier
H:\程序\4\4.cpp(50) : error C2065: 'hInst' : undeclared identifier
H:\程序\4\4.cpp(50) : error C2440: '=' : cannot convert from 'struct HINSTANCE__ *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
H:\程序\4\4.cpp(88) : error C2065: 'sprintf' : undeclared identifier
Error executing cl.exe.
4.obj - 6 error(s), 0 warning(s)
帮我看看,有些疑惑了。。。 展开
#include "stdafx.h"
ATOM MyRegisterClass(HINSTANCE hInstance);
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
BOOL InitInstance(HINSTANCE hInstance,int nCmdShow);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
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_HREDRAM | 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.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);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}
结果编译出现了以下问题,
-------------------Configuration: 4 - Win32 Debug--------------------
Compiling...
4.cpp
H:\程序\4\4.cpp(35) : error C2065: 'CS_HREDRAM' : undeclared identifier
H:\程序\4\4.cpp(40) : error C2065: 'IDI_MOUSEMOVE' : undeclared identifier
H:\程序\4\4.cpp(44) : error C2065: 'IDI_SMALL' : undeclared identifier
H:\程序\4\4.cpp(50) : error C2065: 'hInst' : undeclared identifier
H:\程序\4\4.cpp(50) : error C2440: '=' : cannot convert from 'struct HINSTANCE__ *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
H:\程序\4\4.cpp(88) : error C2065: 'sprintf' : undeclared identifier
Error executing cl.exe.
4.obj - 6 error(s), 0 warning(s)
帮我看看,有些疑惑了。。。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询