日期:2014-05-18 浏览次数:21026 次
Imports System.Runtime.InteropServices Public Class Form1 Public Sub New() InitializeComponent() Me.webhtml.Url = New System.Uri(Application.StartupPath + "\test.html", System.UriKind.Absolute) End Sub Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click Me.webhtml.ShowPageSetupDialog() Me.Text = ("ShowPageSetupDialog") End Sub Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click Me.webhtml.ShowPrintPreviewDialog() End Sub Protected Overrides Sub WndProc(ByRef m As Message) MyBase.WndProc(m) End Sub Dim hook As New Win32Hook() Private Sub hook_onMouseChange(ByVal sender As Object, ByVal e As EventArgs) Try Me.Text = Cursor.Position.ToString() Catch ex As Exception End Try End Sub Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click AddHandler hook.onMouseChange, AddressOf hook_onMouseChange hook.SetHook() End Sub Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click RemoveHandler hook.onMouseChange, AddressOf hook_onMouseChange End Sub End Class Public Class Win32Hook <DllImport("kernel32")> _ Public Shared Function GetCurrentThreadId() As Integer End Function <DllImport("user32", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)> _ Public Shared Function SetWindowsHookEx(ByVal idHook As HookType, ByVal lpfn As HOOKPROC, ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer End Function Public Enum HookType WH_GETMESSAGE = 5 '系统都会调用WH_CBT Hook子程,这些事件包括 End Enum Public Delegate Function HOOKPROC(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer Public Event onMouseChange As System.EventHandler Public Sub SetHook() SetWindowsHookEx(HookType.WH_GETMESSAGE, New HOOKPROC(AddressOf Me.MyKeyboardProc), 0, GetCurrentThreadId()) End Sub Public Function MyKeyboardProc(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer RaiseEvent onMouseChange(Nothing, Nothing) Return 0 End Function End Class
------解决方案--------------------
Timer,tick事件计时!在mousedown事件里触发tick事件!