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

  • 相关阅读:
    系统改造/升级项目的注意点
    phpunit相关
    IE浏览器:定义文档兼容性
    pptx,docx,xlsx 文件下载问题
    常用linux命令
    oracle 子查询写法
    QQ上传大文件为什么这么快
    decimal tostring 格式
    2020HDU多校第三场 1005 Little W and Contest
    火车进栈(进出栈的模拟,dfs爆搜)
  • 原文地址:https://www.cnblogs.com/Believeme/p/1566572.html
Copyright © 2011-2022 走看看