用API函数定义热键又一法
2008-02-23 06:54:01来源:互联网 阅读 ()
三个API函数是必须的:
ReGISterHotKey —— 用于定义热键
UnregisterHotKey —— 用于注销热键
PeekMessage —— 用于检测热键(尚有其它的主要用途)
这里举个实例:程序启动后窗体不可见,按下 Ctrl F12 窗体弹出来。本例仅需要一个窗体,在 PWin98、VB6.0企业版下调试通过。
'申明 API 函数
Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private bCancel As Boolean '用于热键有效与否的变量
'全局变量
Private Const MOD_ALT = &H1
Private Const MOD_CONTROL = &H2
Private Const MOD_SHIFT = &H4
Private Const PM_REMOVE = &H1
Private Const WM_HOTKEY = &H312
Private Type Msg '定义Message类型
hWnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
End Type
Private Sub proMsg() '声明进程
Dim Message As Msg
' 循环直到 bCancel 为真
Do While Not bCancel
'检测到热键被按下则令窗体隐藏
If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
Me.Visible = True
End If
DoEvents
Loop
End Sub
Private Sub Form_Load() '窗体加载时初始化程序
Dim ret As Long
bCancel = False
'定义热键为Ctrl F12
ret = RegisterHotKey(Me.hWnd, &HBFFF&, MOD_CONTROL, vbKeyF12)
Me.Visible = False '窗体不可见
proMsg
End Sub
'退出时注销热键
Private Sub Form_Unload(Cancel As Integer)
bCancel = True
Call UnregisterHotKey(Me.hWnd, &HBFFF&)
End Sub
上一篇: 用Shell语句调出控制面板
下一篇: 检测磁盘类型的信息
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:在VB里巧用数据类型集合
下一篇:基于VB的通用折行打印程序
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash