vb 用快捷键来隐藏和显示窗体

无论窗体有没有焦点,快捷键都要能用。按一下就显示,再按一下就隐藏。代码怎么写呀?我是自己做了个。想用快捷键来隐藏和显示窗体1楼。。。。我汗。。2楼你错了。我不是要同时按键... 无论窗体有没有焦点,快捷键都要能用。按一下就显示,再按一下就隐藏。代码怎么写呀?
我是自己做了个。想用快捷键来隐藏和显示窗体1楼。。。。我汗。。 2楼你错了。我不是要同时按键Form1.Visible = True
Form1.Visible = False
也就是说热只实现这两个功能就可以了。
展开
 我来答
bigshuye
2010-02-28 · TA获得超过2320个赞
知道大有可为答主
回答量:5658
采纳率:0%
帮助的人:4542万
展开全部
http://icese.net/icetool/other/ice203.vb.rar

Ctrl+Alt+3
交替显示隐藏窗体,自己修改即可
英越0iV355
推荐于2017-09-07 · 超过20用户采纳过TA的回答
知道答主
回答量:64
采纳率:0%
帮助的人:31.2万
展开全部
添加两个按钮
Form1代码:
Private Sub Command1_Click()
Form1.Hide
End Sub

Private Sub Command2_Click()
Form1.Show
End Sub

Private Sub Form_Load()
EnableKBDHook
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnHookKBD

End
End Sub
在添加一个模块:点工程在点添加模块
在模块代码里写:
Option Explicit
Public Const WH_KEYBOARD = 13
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Public hNextHookProc As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const BM_CLICK = &HF5
Public Type KBDLLHOOKSTRUCT

vkCode As Long
scanCode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type
Public Sub UnHookKBD()
On Error Resume Next
If hNextHookProc <> 0 Then
UnhookWindowsHookEx hNextHookProc
hNextHookProc = 0
End If
End Sub
Public Function EnableKBDHook()
On Error Resume Next
If hNextHookProc <> 0 Then
Exit Function
End If
hNextHookProc = SetWindowsHookEx(WH_KEYBOARD, AddressOf MyKBHFunc, App.hInstance, 0)
If hNextHookProc <> 0 Then
EnableKBDHook = hNextHookProc
End If
End Function
Public Function MyKBHFunc(ByVal iCode As Long, ByVal wParam As Long, lParam As KBDLLHOOKSTRUCT) As Long
On Error Resume Next
MyKBHFunc = 0
If iCode < 0 Then
MyKBHFunc = CallNextHookEx(hNextHookProc, iCode, wParam, lParam)
Exit Function
End If
If lParam.vkCode = vbKeyHome Then
SendMessage Form1.Command1.hwnd, &HF5, 0, ByVal 0 '这里按下home键就等于按下form1的command1
ElseIf lParam.vkCode = vbKeyEnd Then
MyKBHFunc = 1
SendMessage Form1.Command2.hwnd, &HF5, 0, ByVal 0 '这里按下End键就等于按下form1的command2
MyKBHFunc = 1

Else
Call CallNextHookEx(hNextHookProc, iCode, wParam, lParam)
End If
End Function

你在试试
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式