由用户:ahkUName 分享
; 设置鼠标坐标模式为屏幕坐标 CoordMode "Mouse", "Screen" ; 初始化变量 startX := 0 startY := 0 endX := 0 endY := 0 ; 鼠标按下事件处理函数 ~LButton:: { MouseGetPos(&x, &y) global startX, startY startX := x startY := y } ~LButton Up:: { MouseGetPos(&x, &y) global startX, startY, endX, endY endX := x endY := y ; 计算矩形的宽度和高度 画线条() } 画线条(*){ global startX, startY,endX,endY ; 计算矩形的宽度和高度 width := Abs(endX - startX) height := Abs(endY - startY) ;ToolWindow让窗口图标不显示在任务栏 myGui := Gui("-Caption +AlwaysOnTop +ToolWindow") 矩形句柄:=myGui.Hwnd myGui.Backcolor:="red" ;斜率=(y2-y1)/(x2-x1) 倾斜3度0.03 倾斜1度0.01 ;WinSetRegion "0-" . height-3 . A_Space . width-3 . "-0" . A_Space . width . "-3" . A_Space . "3-" . height . A_Space . "0-" . height-3, 矩形句柄 ;左上成功 ;myGui.Show("x" . startX . "y" . endY . "w" . width . A_Space . "h" . height) ;右下成功 ;myGui.Show("x" . endX . "y" . startY . "w" . width . A_Space . "h" . height) ;WinSetRegion width-3 . "-" . height . A_Space . "0-3" . A_Space . "3-0" . A_Space . width . "-" . height-3 . A_Space . width-3 . "-" . height, 矩形句柄 ;左下成功 ;myGui.Show("x" . startX . "y" . startY . "w" . width . A_Space . "h" . height) ;右上成功 ;myGui.Show("x" . endX . "y" . endY . "w" . width . A_Space . "h" . height) ;左下斜线 x1<x2且y1<y2 if(WinExist(矩形句柄)){ try{ WinClose(矩形句柄) } } if(Abs(endY - startY)<10){ height:=3 if(startX>endX){ myGui.Show("x" . endX . "y" . endY . "w" . width . A_Space . "h" . height) }else if(startX<endX){ myGui.Show("x" . startX . "y" . startY . "w" . width . A_Space . "h" . height) } return } else if(Abs(endX - startX)<10){ width:=3 if(startY>endY){ myGui.Show("x" . endX . "y" . endY . "w" . width . A_Space . "h" . height) }else if(startY<endY){ myGui.Show("x" . startX . "y" . startY . "w" . width . A_Space . "h" . height) } return } if(startY>endY){ ;右上或左上 if(startX>endX){ WinSetRegion width-3 . "-" . height . A_Space . "0-3" . A_Space . "3-0" . A_Space . width . "-" . height-3 . A_Space . width-3 . "-" . height, 矩形句柄 myGui.Show("x" . endX . "y" . endY . "w" . width . A_Space . "h" . height) }else if(startX<endX){ WinSetRegion "0-" . height-3 . A_Space . width-3 . "-0" . A_Space . width . "-3" . A_Space . "3-" . height . A_Space . "0-" . height-3, 矩形句柄 myGui.Show("x" . startX . "y" . endY . "w" . width . A_Space . "h" . height) } return }else if(startY<endY){ ;右下或左下 if(startX>endX){ WinSetRegion "0-" . height-3 . A_Space . width-3 . "-0" . A_Space . width . "-3" . A_Space . "3-" . height . A_Space . "0-" . height-3, 矩形句柄 myGui.Show("x" . endX . "y" . startY . "w" . width . A_Space . "h" . height) }else if(startX<endX){ WinSetRegion width-3 . "-" . height . A_Space . "0-3" . A_Space . "3-0" . A_Space . width . "-" . height-3 . A_Space . width-3 . "-" . height, 矩形句柄 myGui.Show("x" . startX . "y" . startY . "w" . width . A_Space . "h" . height) } return } }
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。
评论(0)