标题:在.net下做一个系统热键,如用CtrL+L关掉form1或停止程式
只看楼主
nhhykly9d2009
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-3-8
 问题点数:0 回复次数:1 
在.net下做一个系统热键,如用CtrL+L关掉form1或停止程式
在.net下做一个系统热键,如用CtrL+L关掉form1或停止程式,
VB6有许多系统热键例子,可惜在VB2005里都不能用了.
不用timer.
搜索更多相关主题的帖子: 热键 程式 CtrL 系统 
2008-03-08 22:06
nhhykly9d2009
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-3-8
得分:0 
我自己来解决
'p 这是窗体设计器中不要修改只能加入代码

    'Form 重写 Dispose,以清理组件列表。
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的
    Private components As

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改它。
    '不要使用代码编辑器修改它。
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
      

    End Sub
   
    '以下是你要加入的代码位置:
    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)
    Const KEYEVENTF_EXTENDEDKEY As Short = &H1S
    Const KEYEVENTF_KEYUP As Short = &H2S
    Const MOUSEEVENTF_LEFTDOWN As Short = &H2S
    Const MOUSEEVENTF_LEFTUP As Short = &H4S
    Const MOUSEEVENTF_MIDDLEDOWN As Short = &H20S
    Const MOUSEEVENTF_ABSOLUTE As Short = &H8000S
    Const MOUSEEVENTF_RIGHTDOWN As Short = &H8S
    Const MOUSEEVENTF_MIDDLEUP As Short = &H40S
    Const MOUSEEVENTF_MOVE As Integer = &H1S
    Const MOUSEEVENTF_RIGHTUP As Short = &H10S
    Public Const WM_CLOSE = &H10
    Friend WithEvents Button1 As System.Windows.Forms.Button
    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

End Class




'这是form1
Public Class Form1
   

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RegisterHotKey(Handle, 0, MOD_CONTROL Or MOD_ALT, Asc("L"))

    End Sub

    Protected Overrides Sub WndProc(ByRef m As Message)
        If m.Msg = WM_HOTKEY Then
            If Visible Then
                Hide()
            Else
                Show()
            End If
        End If
        MyBase.WndProc(m)
    End Sub

    Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
        UnRegisterHotKey(Handle, 0)
    End Sub

End Class
2008-03-10 12:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-202559-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.385607 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved