zoukankan      html  css  js  c++  java
  • .net winfrom 定义全局快捷键!

    public class Test 
    Dim myTimeNow As String
        '全局快捷键
        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
        Private Sub ProcessHotKey(ByVal m As Message)
            Dim id As IntPtr
            id = m.WParam
            Dim sid As String = id.ToString
            Select Case sid
                Case "100"
                    txtTXM.Focus()
                Case "101"
                    txtSL.Focus()
                Case "102"
                    txtDW.Focus()
                Case "103"
                    txtCFH.Focus()
                Case "104"
                    txtSZM.Focus()
                Case "105"
                Case "106"
                Case "107"
                Case "108"
                Case "109"
                Case "110"
                Case "111"
                Case "112"
                    Me.Close()
            End Select
        End Sub
        '通过监视系统消息,来调用过程
        Protected Overrides Sub WndProc(ByRef m As Message)
            If m.Msg = WM_HOTKEY Then
                ProcessHotKey(m)
            End If
            MyBase.WndProc(m)
        End Sub

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            SkinEngine1.SkinFile = Application.StartupPath + "\\Skins\\Longhorn\\Longhorn.ssk"
            DataGridView1.Columns(1).Frozen = True

            '注册热键
            RegisterHotKey(Handle, 100, 0, Keys.F1)
            RegisterHotKey(Handle, 101, 0, Keys.F2)
            RegisterHotKey(Handle, 102, 0, Keys.F3)
            RegisterHotKey(Handle, 103, 0, Keys.F4)
            RegisterHotKey(Handle, 104, 0, Keys.F5)
            RegisterHotKey(Handle, 105, 0, Keys.F7)
            RegisterHotKey(Handle, 106, 0, Keys.F8)
            RegisterHotKey(Handle, 107, 0, Keys.PageUp)
            RegisterHotKey(Handle, 108, 0, Keys.PageDown)
            RegisterHotKey(Handle, 109, 0, Keys.Home)
            RegisterHotKey(Handle, 110, 0, Keys.Delete)
            RegisterHotKey(Handle, 111, 0, Keys.End)
            RegisterHotKey(Handle, 112, 0, Keys.Escape)
        End Sub
        Private Sub frmPmain_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
            '注销热键
            UnRegisterHotKey(Handle, 100)
            UnRegisterHotKey(Handle, 101)
            UnRegisterHotKey(Handle, 102)
            UnRegisterHotKey(Handle, 103)
            UnRegisterHotKey(Handle, 104)
            UnRegisterHotKey(Handle, 105)
            UnRegisterHotKey(Handle, 106)
            UnRegisterHotKey(Handle, 107)
            UnRegisterHotKey(Handle, 108)
            UnRegisterHotKey(Handle, 109)
            UnRegisterHotKey(Handle, 110)
            UnRegisterHotKey(Handle, 111)

        End Sub
    end class

  • 相关阅读:
    横竖屏
    iOS/Android·全球
    POKEMON GO(口袋妖怪)一起玩
    自定义宏
    设置button图片和文字
    iOS10 降级版本到9.几
    1.安装Loucust
    python小程序打包
    Jmeter GIS调用-->参数化+正则表达式提取器+后置处理器+逻辑控制器
    装PIL库
  • 原文地址:https://www.cnblogs.com/Believeme/p/1566572.html
Copyright © 2011-2022 走看看