Re: [.NET] 如何設計滑鼠輔助線
※ 引述《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://www.ptt.cc/bbs/Visual_Basic/M.1431797874.A.6FC.html
※ 編輯: chinoyan (218.166.150.180), 05/17/2015 01:40:39
→
05/17 11:25, , 1F
05/17 11:25, 1F
→
05/18 04:12, , 2F
05/18 04:12, 2F
→
05/18 04:12, , 3F
05/18 04:12, 3F
討論串 (同標題文章)
Visual_Basic 近期熱門文章
PTT數位生活區 即時熱門文章