'按ctrl+F1运行记事本'm1.bas
Declare Function RegisterHotKey Lib "user32" (ByVal Hwnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Declare Function UnregisterHotKey Lib "user32" (ByVal Hwnd As Long, ByVal id As Long) As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal Hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal Hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function GetWindow Lib "user32" (ByVal Hwnd As Long, ByVal wCmd As Long) As LongDeclare Function SetWindowPos Lib "user32" (ByVal Hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongPublic Const GWL_WNDPROC = (-4)
Public Const WM_HOTKEY = &H312Public Const MOD_ALT = &H1
Public Const MOD_CONTROL = &H2
Public Const VK_F1 = &H70
Public Const VK_F2 = &H71
Public Const VK_F3 = &H72
Public Const VK_F4 = &H73
Public Const VK_F5 = &H74
Public Const VK_F6 = &H75
Public Const VK_F7 = &H76
Public Const VK_F8 = &H77
Public Const VK_F9 = &H78
Public Const VK_F10 = &H79
Public Const VK_F11 = &H7A
Public Const VK_F12 = &H7B
Public Const VK_END = &H23Public Oldproc As LongPublic Sub Dof(Index As Integer)
If Index = 0 Then Shell "notepad.exe", vbNormalFocus
End SubPublic Function MyWindowProc(ByVal Hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If iMsg = WM_HOTKEY Then Dof (wParam)
MyWindowProc = CallWindowProc(Oldproc, Hwnd, iMsg, wParam, lParam)
End FunctionSub RegK(Hwnd As Long)
RegisterHotKey Hwnd, 0, MOD_CONTROL, VK_F1
End SubSub UnRegK(Hwnd As Long)
Dim ret As Long, i As Integer
For i = 0 To 20
ret = UnregisterHotKey(Hwnd, i)
Next i
End Sub
'------end of m1.bas
'form1
Private Sub Form_Load()
If App.PrevInstance = True Then
Call MsgBox("Running")
End
Exit Sub
End If
RegK Form1.Hwnd
Oldproc = SetWindowLong(Form1.Hwnd, GWL_WNDPROC, AddressOf MyWindowProc)
End SubPrivate Sub Form_Unload(Cancel As Integer)
UnRegK Form1.Hwnd
Oldproc = SetWindowLong(Form1.Hwnd, GWL_WNDPROC, Oldproc)
End
End Sub
Declare Function RegisterHotKey Lib "user32" (ByVal Hwnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Declare Function UnregisterHotKey Lib "user32" (ByVal Hwnd As Long, ByVal id As Long) As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal Hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal Hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function GetWindow Lib "user32" (ByVal Hwnd As Long, ByVal wCmd As Long) As LongDeclare Function SetWindowPos Lib "user32" (ByVal Hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongPublic Const GWL_WNDPROC = (-4)
Public Const WM_HOTKEY = &H312Public Const MOD_ALT = &H1
Public Const MOD_CONTROL = &H2
Public Const VK_F1 = &H70
Public Const VK_F2 = &H71
Public Const VK_F3 = &H72
Public Const VK_F4 = &H73
Public Const VK_F5 = &H74
Public Const VK_F6 = &H75
Public Const VK_F7 = &H76
Public Const VK_F8 = &H77
Public Const VK_F9 = &H78
Public Const VK_F10 = &H79
Public Const VK_F11 = &H7A
Public Const VK_F12 = &H7B
Public Const VK_END = &H23Public Oldproc As LongPublic Sub Dof(Index As Integer)
If Index = 0 Then Shell "notepad.exe", vbNormalFocus
End SubPublic Function MyWindowProc(ByVal Hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If iMsg = WM_HOTKEY Then Dof (wParam)
MyWindowProc = CallWindowProc(Oldproc, Hwnd, iMsg, wParam, lParam)
End FunctionSub RegK(Hwnd As Long)
RegisterHotKey Hwnd, 0, MOD_CONTROL, VK_F1
End SubSub UnRegK(Hwnd As Long)
Dim ret As Long, i As Integer
For i = 0 To 20
ret = UnregisterHotKey(Hwnd, i)
Next i
End Sub
'------end of m1.bas
'form1
Private Sub Form_Load()
If App.PrevInstance = True Then
Call MsgBox("Running")
End
Exit Sub
End If
RegK Form1.Hwnd
Oldproc = SetWindowLong(Form1.Hwnd, GWL_WNDPROC, AddressOf MyWindowProc)
End SubPrivate Sub Form_Unload(Cancel As Integer)
UnRegK Form1.Hwnd
Oldproc = SetWindowLong(Form1.Hwnd, GWL_WNDPROC, Oldproc)
End
End Sub
解决方案 »
- 关于加载外部对象的困惑
- 我装VS6 提示什么 ACM无法安装 怎么回事 以前都好好的 重装过系统了
- VB 中一个简单的关于向数据库中存取图片的问题——————在线等待!!!!(初学者)
- 请问,像QQ那样的好友分类栏(一点击就可以上下切换),在VB里用哪个控件可以实现?
- 怎样将字符串转换成表达式,急急急!!!
- Flash控件的右键菜单,怎么屏蔽掉?
- 请问datagrid 数据集再过滤问题
- 如何用一个记录集中的若干列组成一个新的recordset?
- 关于****图标****的API函数问题
- 重金悬赏!!大洋200!!言者有分!!
- 请问屏蔽键盘输入用那个API?
- 调用一个系统程序,已经实现,但我要它自动进行"yes"
The RegisterHotKey function defines a system-wide hot key. BOOL RegisterHotKey(
HWND hWnd, // handle to window
int id, // hot key identifier
UINT fsModifiers, // key-modifier options
UINT vk // virtual-key code
);
Parameters
hWnd
[in] Handle to the window that will receive WM_HOTKEY messages generated by the hot key. If this parameter is NULL, WM_HOTKEY messages are posted to the message queue of the calling thread and must be processed in the message loop.
id
[in] Specifies the identifier of the hot key. No other hot key in the calling thread should have the same identifier. An application must specify a value in the range 0x0000 through 0xBFFF. A shared dynamic-link library (DLL) must specify a value in the range 0xC000 through 0xFFFF (the range returned by the GlobalAddAtom function). To avoid conflicts with hot-key identifiers defined by other shared DLLs, a DLL should use the GlobalAddAtom function to obtain the hot-key identifier.
fsModifiers
[in] Specifies keys that must be pressed in combination with the key specified by the nVirtKey parameter in order to generate the WM_HOTKEY message. The fsModifiers parameter can be a combination of the following values. Value Meaning
MOD_ALT Either ALT key must be held down.
MOD_CONTROL Either CTRL key must be held down.
MOD_SHIFT Either SHIFT key must be held down.
MOD_WIN Either WINDOWS key was held down. These keys are labeled with the Microsoft Windows logo.
vk
[in] Specifies the virtual-key code of the hot key.
Return Values
If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, call GetLastError.