首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

用GetAsyncKeyState实现隐藏与重现的有关问题

2012-02-01 
用GetAsyncKeyState实现隐藏与重现的问题我想用GetAsyncKeyState仅用一个键来实现窗体的隐藏与重现,比如下

用GetAsyncKeyState实现隐藏与重现的问题
我想用GetAsyncKeyState仅用一个键来实现窗体的隐藏与重现,比如下面代码就用"0"来实现
Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer

Private Function MyHotKey(vKeyCode) As Boolean ' 声明的自定义函数
  
  MyHotKey = GetAsyncKeyState(vKeyCode) < 0 '结果的高位指出该键当前是否被按下(是为1,否为0)故按下为负,未按为0

End Function



Private Sub Timer1_Timer()
 Static a As Boolean
 If (MyHotKey(vbKey0) And (Not a)) Then '第一次按下,隐藏.
  Me.Hide
  a = True
   
 End If
   
 If (MyHotKey(vbKey0) And a) Then '第二次按下,重现.
  
  Me.Show
  a = False
   
 End If
End Sub

不过不知怎么回事竟然实现不了,哪位高手帮忙解释下,顺便给个可以用一个键实现隐藏与重现的方法,谢谢了~~


[解决办法]
‘优化’一下:

VB code
Option ExplicitPrivate Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As IntegerPrivate Function MyHotKey(vKeyCodeas As Long) As Boolean    MyHotKey = GetAsyncKeyState(vKeyCodeas) < 0End FunctionPrivate Sub Timer1_Timer()    Static a As Boolean    If (MyHotKey(vbKey0)) Then        Me.Visible = a: a = Not a        While (MyHotKey(vbKey0))            DoEvents        Wend    End IfEnd Sub 

热点排行