作者chinoyan ()
看板Visual_Basic
标题Re: [.NET] 如何设计滑鼠辅助线
时间Sun May 17 01:37:51 2015
※ 引述《cool21540125 (cool21540125)》之铭言:
: 请输入专案类型(网站专案或者应用程式专案):
: 在公司常要开启某些财务报表,而有些数字都是密密麻麻的
: 因此,希望自写一款有「滑鼠辅助线」功能的程式
: 当程式启动时,萤幕上会出现一横一竖的直线,以滑鼠的箭头为交叉点(有点像狙击镜)
: 滑鼠移到哪,辅助线就会以滑鼠指标为中心跟着移动
: 想请教各位前辈们,我想利用VB2010来撰写
: 需要先从哪个方向作开始?
: 自己写程式都只会写一些资料处理方面的应用...
: 所以像是移动滑鼠,绘图...自己几乎是个新手
: 麻烦给个方向,感谢!
最简单的做法,几个API而己,没有那麽难(VB6)
Option Explicit
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal
hdc As Long) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As
Long, ByVal y As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As
Long, ByVal y As Long, lpPoint As Any) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As
Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long)
As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Dim Dc As Long
Dim P0 As POINTAPI, P As POINTAPI
Private Sub Form_Load()
Dc = GetDC(0)
Me.WindowState = 2
Timer1.Interval = 10
Me.Hide
End Sub
Private Sub Form_Unload(Cancel As Integer)
ReleaseDC 0, Dc
End Sub
Private Sub Timer1_Timer()
GetCursorPos P
If Abs(P0.x - P.x) > 1 Or Abs(P0.y - P.y) > 1 Then
P0 = P
'Form1.Caption = "mouse Cursor at " + CStr(P.x) + "," + CStr(P.y)
Me.Show
DoEvents
Me.Hide
MoveToEx Dc, 0, P.y, 0
LineTo Dc, GetSystemMetrics(0&), P.y
MoveToEx Dc, P.x, 0, 0
LineTo Dc, P.x, GetSystemMetrics(1&)
End If
End Sub
--
████ █ ★ ████ █ █ █
█ █ █ █ █ █ 超 级 热 烈 欢 迎
█ ████ █ █ █ ████ █
█ █ █ █ ███★ █ █ 欢迎到嘉义版!
★███ █ █ █ █ █ █ █
讯驰电脑-路径 →
嘉义市林森西路496号 →
(05)2244-526 →
顺发斜对面
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 218.166.150.180
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Visual_Basic/M.1431797874.A.6FC.html
※ 编辑: chinoyan (218.166.150.180), 05/17/2015 01:40:39
1F:→ MOONRAKER: 对新手而言一点教学意义都没有 05/17 11:25
2F:→ chinoyan: 我都没用hook了,几个api应用,google一下就懂了, 05/18 04:12
3F:→ chinoyan: 范例都给了,只要肯GOOGLE,API的用途,怎麽会没意义 05/18 04:12