怎么用vb实现老板键功能呢

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了怎么用vb实现老板键功能呢相关的知识,希望对你有一定的参考价值。

帮忙给出代码,谢!

要做老板键的功能必须包含2个要素

1,快捷键截取
2,隐藏窗口

1.快捷键的截取

先将下面代码,复制到一个模块中

'Option Explicit

'********************************************************
' DECLARATIONS NEEDED TO INTERCEPT WINDOW MESSAGES *
'********************************************************
Public Type POINTAPI
x As Long
Y As Long
End Type
Public Const PROCESS_ALL_ACCESS = &H1F0FFF
Global P As POINTAPI
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal Y As Long) As Long
Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long

Public Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal Y As Long) As Long
Public Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Public Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal OldwndProc As Long, ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Const GWL_WNDPROC = -4
Public OldwndProc As Long

'********************************************************
' DECLARATIONS NEEDED TO CREATE THE HOTKEY *
'********************************************************

Public Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal HotKeyID As Long, ByVal fsModifiers As Long, ByVal vKey As Long) As Long
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal HotKeyID As Long) As Long

Public Const WM_HOTKEY = &H312
Public Const WM_NCDESTROY = &H82

Public HotKeyID(12) As Long

Public Function WindowProc(ByVal hWnd As Long, ByVal WindowMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

'This is where all the messages for this form as directed to
'We will need to check for the WindowMessage WM_HOTKEY
'to see if a hotkey is pressed and then we need
'To check the wParam to see which HotKey (1-12) has been pressed

Select Case WindowMsg
Case WM_HOTKEY
Select Case wParam
'This is where you put the code you want to start
'whenever someone has pressed a hotkey
Case HotKeyID(1)
Call BgenOEnd(0)
Case HotKeyID(2)
Call BgenOEnd(1)
Case HotKeyID(3)
Call BgenOEnd(2)
End Select
End Select

'No matter what happens we *always* end with the normal
'window procedure to finish/handle the message by
'calling the CallWindowProc.
WindowProc = CallWindowProc(OldwndProc, hWnd, WindowMsg, wParam, lParam)

End Function

Function BgenOEnd(lolo As Long) '开始和暂停

'这里处理接受到快捷键后的方法
'如果要隐藏窗口,直接使用 form.hide即可
'如果窗口已经被隐藏,那么直接使用form.show即可
End Function

------------------------------------------------------------

在启动窗体中加入以下事件

Dim HotKeyEnabled(12) As Boolean
Dim HotKey As Byte
Public Sub CleanUp()

For HotKey = 1 To 12
If HotKeyEnabled(HotKey) = True Then
Call DeleteHotkey
End If
Next HotKey

Unload Me

'Don't end with End since this will cause the program to crash
'even if you restored the SetWindowLong property to the OldwndHnd

End Sub

Public Sub CreateHotkey()

Dim ReturnValue As Long

'The Hotkey will need an ID since there are several
'hotkeys you will want know which one has been pressed

'To keep it simple, we will keep the ID number the same
'as the Function key number that has been selected

HotKeyID(HotKey) = HotKey

'There are 12 function keys. The Ascii number for
'Function-Key 1 = 112
'So if we add 111 to our Hotkey number we know the value
'of the function key that will be the hotkey
HotKey = HotKey + 111
ReturnValue = RegisterHotKey(hWnd, HotKeyID(HotKey - 111), 1, HotKey)
'Now that we know the value and ID of the key to register as a
'HotKey we can actually register the key as a hotkey

'(note: since we added 111 to HotKey we will need to subtract it again
' to get the right HotKey number for the ID)

End Sub

Public Sub DeleteHotkey()

Dim ReturnValue As Long

'To disable/unload the selected hotkey (index number of the checkbox
'that was clicked on) simply unregister the HotKeyID (from the form it
'was registered to)
ReturnValue = UnregisterHotKey(hWnd, HotKeyID(HotKey))

End Sub

然后在窗口的load事件中加入以下代码

For i = 0 To 2
HotKey = i + 1
Call CreateHotkey 'Go to the CreateHotKey sub to actually create the hotkey
HotKeyEnabled(i + 1) = True
Next i

这里的hotkey是f1-f12
参考技术A Me.BorderStyle = 0
Me.WindowState = 1
参考技术B 只要做一个图片,比如word 在编辑中状态.
用VB设定一个热键,把图片放大到全屏.
就看上去你正在做事.
参考技术C 首先把Form的ShowInTaskBar属性改为False。我设置的老板键是′,也就是1左边那个键。隐藏后,屏幕上看似没有这个程序,但是,把其他程序都最小化后,你会在屏幕左下角发现一个小条,这里可以还原。
代码如下。
=================
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 96 Then WindowState = vbMinimized
End Sub
参考技术D me.hide 第5个回答  2008-08-17 查一下关于双explorer的说明。。

怎么样在vb中设置statusbar?

如楼上所说,先引用控件
然后拉一个到窗体,右键点到上看属性,很直观

如果想用程序实现

增加一个窗格
StatusBar1.Panels.Add 2, , "text",style
其中2为序号,是第几个窗格就写几,"text"是要显示的内容,它决定于你选择的style,具体的style你可以点状态栏的属性看

修改窗格,i代表序号
StatusBar1.Panels(i).Text = ""
StatusBar1.Panels(i).Style = sbrText

窗格类型 style
sbrText 显示文本内容
sbrDate 显示当前日期
sbrTime 显示当前时间
常用的就这些,还有sbrCaps,sbrNum 显示键CAPS,NUM等是否被选中
参考技术A 在部件里引用Microsoft Windows Common Controls
在控件条上就会有一堆新东西,里面有statusbar

以上是关于怎么用vb实现老板键功能呢的主要内容,如果未能解决你的问题,请参考以下文章

MFC老板键注册

MFC老板键注册

软件的老板快捷键

分布式|老板让我实现附近人发现的功能,我用它实现了

hihernate一对多关联映射

在VB里怎么用sendmessage实现组合键ctrl+end,要确实可行的办法,请写下详细代码