求助,如何用processing来控制鼠标点击

求助,如何用processing来控制鼠标点击,第1张

可以用mouseX变量获得鼠标在X轴的值,mouseY变量获得鼠标在Y轴的值。下面是一个最简单的鼠标跟踪互动程序。

void setup()

{

size(480,120);

fill(0,102);

smooth(); //smooth()函数可以让画出的图形的边缘更平滑,同学们可以将这个语句注释后,//看看画图效果的变化。

noStroke(); //图形只有填充色,没有边框

}

void draw()

{

ellipse(mouseX,mouseY,9,9);

}

word把画笔变成鼠标模式

1、打开word文档;

2、点击工具栏的“插入”,点击下拉菜单的“表格”;

3、点击表格下端的“小三角”在d出的菜单里点击“绘制表格”。这样鼠标就变成笔了。

1设置一个数组,记录鼠标位置和方圆标记和方圆大小,每点一次记录一个,然后发送绘制消息。

2在重画消息处理里,只重画最新点位图形大小的部分,如果全部重绘,速度慢,还会有闪烁,如果设置得当会出现动画效果。

3这种简单的图形处理效果不会太好,只是用于理解图形编程原理,如果动画则有专门的动画处理图形库,效果会更好。

呵呵,哥们,我们也刚学完这些,以下代码给你,要的基本符合,不过你得要在加2个资源(在insert的resource中)“鼠标的(cursor)和菜单栏的(menu)”,不加是不行的,加了后该修改的你能看的懂的,实在不行,我就直接发文件给你:

#include <windowsh>

#include "resourceh"

#include <stringh>

#include <stdioh>

#include <mathh>

HINSTANCE g_hInstance;

int g_nToolID = 0;

struct tagLine

{

POINT ptB;

POINT ptE;

bool bIsDelete;

};

tagLine g_AllLines[100];//直线数组

int g_nLineNumber = 0; //实际直线数

struct tagCircle

{

POINT ptCenter;

int nRadius;

bool bIsDelete;

};

tagCircle g_AllCircles[100];//整圆数组

int g_nCircleNumber = 0; // 实际保存的圆个数

POINT pt1 = {200,200};

POINT pt2 = {200,200};

POINT pt3 = {0,0};

int g_nState = 0;

//功能:画一线直线段

void DrawLine(HDC hDC,POINT ptB,POINT ptE)

{

::MoveToEx(hDC,ptBx,ptBy,NULL);

::LineTo(hDC,ptEx,ptEy);

}

//功能:已知两点求距离

int Distance(POINT pt1,POINT pt2)

{

int nR = 0;

nR=sqrt((pt1x - pt2x)(pt1x - pt2x) +(pt1y - pt2y)(pt1y- pt2y));

return nR;

}

void DrawCircle(HDC hDC,POINT ptC,int nR)

{

::Ellipse(hDC,ptCx - nR,ptCy - nR,ptCx + nR,ptCy + nR);

}

void OnMouseMove(POINT ptPos,HWND hWnd)

{

if(g_nToolID == ID_CIRCLE)

{

if(g_nState == 1)

{

HDC hDC = ::GetDC(hWnd);

//取得系统预定义一个“空心刷子”

HBRUSH hBrush = (HBRUSH)::GetStockObject(NULL_BRUSH);

::SelectObject(hDC,hBrush);

::SetROP2(hDC,R2_NOTXORPEN);

DrawLine(hDC,pt1,pt2);

int nR = Distance(pt1,pt2);

DrawCircle(hDC,pt1,nR);

pt3 = ptPos;

nR = Distance(pt1,pt3);

DrawCircle(hDC,pt1,nR);

DrawLine(hDC,pt1,pt3);

pt2 = pt3;

::ReleaseDC(hWnd,hDC);

}

}else if(g_nToolID == ID_LINE)

{

if(g_nState == 1)

{

HDC hDC = ::GetDC(hWnd);

pt3=ptPos;

//用背景色,绘制上一次的位置==>擦除

::SetROP2(hDC,R2_NOTXORPEN);

::DrawLine(hDC,pt1,pt2);

::DrawLine(hDC,pt1,pt3);

pt2 = pt3;

::ReleaseDC(hWnd,hDC);

}

}

}

void OnLButtonUp(POINT ptPos)

{

if(g_nToolID == ID_CIRCLE)

{

if(g_nState == 1)

{

tagCircle aCir;

aCirptCenter = pt1;

aCirnRadius = Distance(pt1,ptPos);

aCirbIsDelete = false;

g_AllCircles[g_nCircleNumber] = aCir;

g_nCircleNumber = g_nCircleNumber + 1;

g_nState = 0;

}

}else if(g_nToolID == ID_LINE)

{

if(g_nState == 1)

{

g_nState = 0;

tagLine aLine;

aLineptB = pt1;

aLineptE = pt3;

aLinebIsDelete = false;

g_AllLines[g_nLineNumber] = aLine;

g_nLineNumber = g_nLineNumber + 1;

}

}

}

//功能:判断点是否在直线段上

bool PtOnCircle(POINT pt,POINT ptC,int nR)

{

int nL = Distance(pt,ptC);

if( fabs(nL - nR) < 5 )

{

return true;

}else

{

return false;

}

}

//功能:判断点是否在直线段上

bool PtOnLine(POINT pt,POINT ptB,POINT ptE)

{

int nL1 = Distance(pt,ptB);

int nL2 = Distance(pt,ptE);

int nL3 = Distance(ptB,ptE);

if( fabs(( nL1 + nL2 ) - nL3) < 5 )

{

return true;

}else

{

return false;

}

}

void OnLButtonDown(HWND hWnd,POINT ptPos)

{

if(g_nToolID == ID_CIRCLE)

{

if(g_nState == 0)

{

g_nState = 1;

pt2 = pt1 = ptPos;

}

}else if(g_nToolID == ID_LINE)

{

if(g_nState == 0)

{

g_nState = 1;

pt2 = pt1 = ptPos;

}

}else if(g_nToolID == ID_DELETE)

{

//判断当前鼠标点是否在某一个直线段上

for(int nI = 0; nI < g_nLineNumber; nI = nI + 1)

{

tagLine pLine = &g_AllLines[nI];

if(PtOnLine(ptPos,(pLine)ptB,(pLine)ptE))

{

char cTxt[100];

sprintf(cTxt,"nI = %d\n",nI);

::OutputDebugString(cTxt);

(pLine)bIsDelete = true;

break;

}

}

//判断当前鼠标点是否在某一个圆上

for(nI = 0; nI < g_nCircleNumber; nI = nI + 1)

{

tagCircle pCircle = &g_AllCircles[nI];

if(PtOnCircle(ptPos,(pCircle)ptCenter,(pCircle)nRadius))

{

(pCircle)bIsDelete = true;

break;

}

}

::InvalidateRect(hWnd,NULL,TRUE);

}

}

void OnPaint(HDC hDC)

{

// 1重绘圆

//取得系统预定义一个“空心刷子”

HBRUSH hBrush = (HBRUSH)::GetStockObject(NULL_BRUSH);

::SelectObject(hDC,hBrush);

for(int nI = 0; nI < g_nCircleNumber; nI++)

{

tagCircle aCir;

aCir = g_AllCircles[nI];

if(aCirbIsDelete == false)

{

DrawCircle(hDC,aCirptCenter,aCirnRadius);

}

}

// 2重绘直线段

for(nI = 0; nI < g_nLineNumber; nI = nI + 1)

{

tagLine aLine = g_AllLines[nI];

if(aLinebIsDelete == false)

{

::DrawLine(hDC,aLineptB,aLineptE);

}

}

}

void OnCommand(HWND hWnd,int nCmdID)

{

switch(nCmdID)

{

case ID_EXIT:

::DestroyWindow(hWnd);

break;

case ID_LINE:

g_nToolID = ID_LINE;

break;

case ID_CIRCLE:

g_nToolID = ID_CIRCLE;

break;

case ID_DELETE:

g_nToolID = ID_DELETE;

break;

}

}

// 窗口回调函数

int WndProc(HWND hWnd,

int message,

int wParam,

int lParam)

{

switch (message)

{

case WM_SETCURSOR:

{

HCURSOR hCur1 = ::LoadCursor(g_hInstance,"pen_cursor");

HCURSOR hCur2 = ::LoadCursor(g_hInstance,"hand_cursor");

HCURSOR hCur3 = ::LoadCursor(g_hInstance,"point_cursor");

HCURSOR hCur4 = ::LoadCursor(g_hInstance,"arrow_cursor");

switch(g_nToolID)

{

case ID_LINE:

::SetCursor(hCur1);

break;

case ID_CIRCLE:

::SetCursor(hCur2);

break;

case ID_DELETE:

::SetCursor(hCur3);

break;

default:

::SetCursor(hCur1);

}

break;

}

case WM_COMMAND:

{

int nID = LOWORD(wParam);

OnCommand(hWnd,nID);

break;

}

case WM_LBUTTONDOWN:

{

POINT ptPos;

ptPosx = LOWORD(lParam);

ptPosy = HIWORD(lParam);

OnLButtonDown(hWnd,ptPos);

}

break;

case WM_LBUTTONUP:

{

POINT ptPos;

ptPosx = LOWORD(lParam);

ptPosy = HIWORD(lParam);

OnLButtonUp(ptPos);

}

break;

case WM_MOUSEMOVE:

{

POINT ptPos;

ptPosx = LOWORD(lParam);

ptPosy = HIWORD(lParam);

OnMouseMove(ptPos,hWnd);

}

break;

case WM_PAINT:

{

PAINTSTRUCT ps;

HDC hDC = ::BeginPaint(hWnd,&ps);

OnPaint(hDC);

::EndPaint(hWnd,&ps);

break;

}

case WM_DESTROY: //窗口关闭时发送

::PostQuitMessage(0); //在消息队列的尾部添加一个0消息,以示,结束程序

break;

default:

return ::DefWindowProc(hWnd, message, wParam, lParam);

}

return 0;

}

int WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

char lpCmdLine,

int nCmdShow)

{

g_hInstance = hInstance;

WNDCLASSEX wcex;

wcexcbSize = sizeof(WNDCLASSEX);

wcexstyle = CS_HREDRAW | CS_VREDRAW;

wcexlpfnWndProc = (WNDPROC)WndProc;

wcexcbClsExtra = 0;

wcexcbWndExtra = 0;

wcexhInstance = hInstance;

wcexhIcon = NULL;

wcexhCursor = LoadCursor(NULL, IDC_ARROW);

wcexhbrBackground = (HBRUSH)(COLOR_WINDOW+1);

wcexlpszMenuName = "menu1";

wcexlpszClassName = "ABCDE";

wcexhIconSm = NULL;

RegisterClassEx(&wcex);

HWND hWnd = CreateWindow("ABCDE",

"WanJie",

WS_OVERLAPPEDWINDOW,

50, 50, //(x,y)

500, 500, // (w,h)

NULL,

NULL,

hInstance,

NULL);

ShowWindow(hWnd,SW_SHOW);

MSG msg;

while (GetMessage(&msg, NULL, 0, 0))

{

DispatchMessage(&msg);

}

return 1;

}

点右键,然后点打开方式,点选择程序,点在列表中选择程序,然后点浏览,找到你的画图的地址,然后点确定,然后再按确定就可以了。

至于怎么找画图的地址,你可以右键点画图的图标,然后点属性,在目标一栏可以看到地址。

以上就是关于求助,如何用processing来控制鼠标点击全部的内容,包括:求助,如何用processing来控制鼠标点击、word把画笔变成鼠标模式了、Windows程序设计怎么鼠标点一下画一个点点一下画一个点等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10216035.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-06
下一篇 2023-05-06

发表评论

登录后才能评论

评论列表(0条)

保存