首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

紧急怎么扑捉屏幕上的鼠标所在位置的坐标和记录下来,并判断鼠标的左键还是右键动作记录下来

2012-04-03 
紧急,如何扑捉屏幕上的鼠标所在位置的坐标和记录下来,并判断鼠标的左键还是右键动作记录下来如何扑捉屏幕

紧急,如何扑捉屏幕上的鼠标所在位置的坐标和记录下来,并判断鼠标的左键还是右键动作记录下来
如何扑捉屏幕上的鼠标所在位置的坐标和记录下来,并判断鼠标的左键还是右键动作记录下来,代码详细点,在线等,能达到要求马上结贴,谢谢

mymail:       cyanhua@sina.com

[解决办法]
我前段时间写了个你自己修改下吧

下面是窗体代码
Option Explicit
Private Declare Function ShowWindow Lib "user32 " (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function SetParent Lib "user32 " (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function FindWindow Lib "user32 " Alias "FindWindowA " (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function MoveWindow Lib "user32 " (ByVal hwnd As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Private Declare Function ClientToScreen Lib "user32 " (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function FindWindowEx Lib "user32 " Alias "FindWindowExA " (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetClientRect Lib "user32 " (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function MessageBox Lib "user32 " Alias "MessageBoxA " (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Sub cmdExit_Click()
Unload Me
End Sub

Private Sub cmdLeave_Click()
Dim lngStart As Long, lngStartButton As Long, objPoint As POINTAPI, objRect As RECT
Me.Hide
lngStart = FindWindow( "Shell_TrayWnd ", vbNullString)
SetParent lngCmdhWnd, lngStart
lngStartButton = FindWindowEx(lngStart, 0, "button ", vbNullString)
'ClientToScreen lngStartButton, objPoint
GetClientRect lngStartButton, objRect
MoveWindow lngCmdhWnd, 0, 0, objRect.Right - objRect.Left, objRect.Bottom - objRect.Top, 1
End Sub

Public Sub cmdSend_Click()
' MessageBox Me.hwnd, "我能响应事件!! ", "哈哈!! ", vbInformation
' ShowWindow Me.hwnd, 5
' SetParent lngCmdhWnd, Me.hwnd
' cmdSend.Move 1800, 2880, cmdExit.Width, cmdExit.Height
PopupMenu Me.mnuOpen
End Sub

Private Sub cmdSend_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 27 Then
SetParent lngCmdhWnd, Me.hwnd
cmdSend.Move 1800, 2880, cmdExit.Width, cmdExit.Height
Me.Show
End If
End Sub

Private Sub Form_Load()
lngCmdhWnd = Me.cmdSend.hwnd
hHook = SetWindowsHookEx(WH_MOUSE_DLL, AddressOf MouseProc, App.hInstance, 0)
End Sub

Private Sub Form_Unload(Cancel As Integer)
UnhookWindowsHookEx hHook
End Sub

Private Sub mnuCalc_Click()
Shell "calc ", vbNormalFocus
End Sub

Private Sub mnuNote_Click()
Shell "Notepad.exe ", vbNormalFocus
End Sub

[解决办法]
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos Lib "User32 " (lpPoint As POINTAPI) As Long
Dim MyPos As POINTAPI
Private Sub Timer1_Timer()
GetCursorPos MyPos '获取光标位置
Text1 = MyPos.X
Text2 = MyPos.Y


End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case Button
Case vbLeftButton
Debug.Print "你在屏幕 " & MyPos.X & ", " & MyPos.Y & " 按鼠标左键 "
Case vbRightButton
Debug.Print "你在屏幕 " & MyPos.X & ", " & MyPos.Y & "按鼠标右键 "
End Select
End Sub

热点排行