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

怎么实现热键

2012-01-07 
如何实现热键如何实现热键[解决办法]VB.NET code用来实现热键呼出效果的Public Const WM_HOTKEY &H312P

如何实现热键
如何实现热键

[解决办法]

VB.NET code
   '用来实现热键呼出效果的    Public Const WM_HOTKEY = &H312    Public Const MOD_ALT = &H1    Public Const MOD_CONTROL = &H2    Public Const MOD_SHIFT = &H4    Public Const GWL_WNDPROC = (-4)    Public Declare Auto Function RegisterHotKey Lib "user32.dll" Alias _        "RegisterHotKey" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Boolean    Public Declare Auto Function UnRegisterHotKey Lib "user32.dll" Alias _        "UnregisterHotKey" (ByVal hwnd As IntPtr, ByVal id As Integer) As Boolean    Dim intTimerMax As Integer    Dim TimeOut As Boolean    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        '用来实现热键呼出效果的        Dim isResult As Boolean        isResult = RegisterHotKey(Handle, 0, MOD_ALT, 0)        If isResult = False Then            MsgBox("注册热键Ctrl+F失败。", , "零拾")        End If        TimeOut = True        Debug.Write("start ")    End Sub    Protected Overrides Sub WndProc(ByRef m As Message) '用来实现热键呼出效果的        If m.Msg = WM_HOTKEY Then            Debug.Write(m.Msg.ToString & " ")            If TimeOut = True Then                TimeOut = False                intTimerMax = 0                Timer_HotKey.Interval = 1                Timer_HotKey.Start()            Else                If Me.Visible = True Then                    Debug.Write("hide ")                    'Me.ShowInTaskbar = False                    Me.Hide()                    'Me.WindowState = FormWindowState.Minimized                Else                    Debug.Write("show ")                    Me.ShowInTaskbar = True                    Me.Show()                    Me.WindowState = FormWindowState.Normal                End If                TimeOut = True            End If        End If        MyBase.WndProc(m)    End Sub    Private Sub Timer_HotKey_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer_HotKey.Tick        intTimerMax = intTimerMax + 1        If intTimerMax = 100 Then            Timer_HotKey.Stop()            TimeOut = True        End If    End Sub 

热点排行