用VC++实现功能

来源:百度知道 编辑:UC知道 时间:2024/05/07 05:05:14
我要用VC++实现功能:鼠标左键按下----记录起点坐标,鼠标左键按下----记录终点坐标;然后在此之间画一条直线。可是我的程序始终出错,盼高手帮我解决一下~~
现程序如下:
#include<windows.h>
LRESULT CALLBACK WndProc(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=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,

1、你的case后面没有break。

2、还有你的float points[]={{x1,y1},{x2,y2}};有问题,建议坐标用CPoint类型,
CPoint fisrt_point;
CPoint last_point;
用法,看看MSDN,很简单的

CPoint Point;
Point.x=~;point.y=~~;
CPoint是MFC的一个类,和Windows的Point结构体是类似的。C++中类和结构体是相通的。
Point结构体的定义如下:
typedef struct tagPOINT {
LONG x;
LONG y;
} POINT;
在使用用结构体中的成员的的时候要用Point.x Point.y
那用CPont类的时候是不是也要这样用呢,那是当然了。
在这里 CPoint Point; 就是实例化了一个CPoint类的对象 然后调用对象的成员。
另外要说明的是CPoint类和CSize类也是类似的,二者的操作可以互换,更多信息,请参看MSDN。

头文件要#include<afxwin.h>,把#include<windows.h>注释掉。

具体好像还有些格式错误吧,类似应该有返回值,你没有返回等等,自己找错吧。(也是一种提高)。