在VB中的窗体Visible=false隐藏了,有没有方法可以弄个快捷健按出来呢?

本人是刚刚开始学VB的,在看教程,可以把窗体隐藏都弄不出来,,进程那还有。。请问有什么方法加个快捷健呢?代码是怎么写呢?谢谢... 本人是刚刚开始学VB的,在看教程,可以把窗体隐藏都弄不出来,,进程那还有。。请问有什么方法加个快捷健呢?代码是怎么写呢?谢谢 展开
 我来答
匿名用户
2013-11-01
展开全部
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 = Not Me.Visible
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
---------------'按ALT+F4隐藏 / 显示窗体
匿名用户
2013-11-01
展开全部
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As IntegerPrivate Sub Form_Load()
Me.Hide
Timer1.Interval = 20
Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyA) = -32768 Then
Me.Show
End If
End Sub'把以上大夫代码复制到一个新的工程,在窗体上添加一个 Timer 控件,按A就可以显示被隐藏的窗体
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式