第一个问题:
想知道以下3个Api函数的详细解释:
1.SetWindowsHookEx
2.UnhookWindowsHookEx
3.CallNextHookEx
(不用费劲去Msdn找了,Api参考手册居然都没有,晕)
第二个问题(还是我提问过多次的那个老问题):
我想在资源管理器窗口上 再加上一个Toolbar,(我看到过有些软件做到了,而且添加的Toolbar中还有启动程序的按钮,比如 金山独霸),请问在注册表中的那里更改可以做到?
是不是还有朋友不明白我的意思?就是这样的:
在 资源管理器 工具条上按鼠标键,出来菜单选择“链接”,你看,是不是多了一个Toolbar出来?我想自己添加一个类似于"链接"的Toolbar到资源管理器上的工具条,我想应该是在注册表中修改或添加某个键值来做到的.
当然,不一定要添加Toolbar,添加一个按纽也可以,不过我想不太可能.呵呵.
还有,不是对IE来操作,是对资源管理器的操作!(有朋友总是告诉我在IE上添加按纽,不是我想要的.)
请赐教,回答出来或提供思路200分相送!UP也有份!!
最新消息:现在我已经知道了注册表中这个地方
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Toolbar
下增加一些键值能够达到效果,(就是会在鼠标右键菜单中出来Toolbar的自定义过的选单),可是现在我并不会自己增加键值,请教高人!
1.SetWindowsHookEx
【VB声明】
Private 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
【别名】
SetWindowsHookExA
实例
In a module
Public Const WH_KEYBOARD = 2
Public Const VK_SHIFT = &H10
Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
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
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public hHook As Long
Public Function KeyboardProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
if idHook is less than zero, no further processing is required
If idHook < 0 Then
call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
Else
check if SHIFT-S is pressed
If (GetKeyState(VK_SHIFT) And &HF0000000) And wParam = Asc("S") Then
show the result
Form1.Print "Shift-S pressed ..."
End If
call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
End If
End Function
In a form, called Form1
Private Sub Form_Load()
KPD-Team 2000
URL: http://www.allapi.net/
E-Mail: KPDTeam@Allapi.net
set a keyboard hook
hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, App.hInstance, App.ThreadID)
End Sub
Private Sub Form_Unload(Cancel As Integer)
remove the windows-hook
UnhookWindowsHookEx hHook
End Sub
SetWindowsHookEx,UnhookWindowsHookEx,CallNextHookEx谁说在MSDN中没有说明的?这三个函数和钩子函数有关,SetWindowsHookEx用于设置一个钩子函数,UnhookWindowsHookEx用于卸载一个钩子函数,CallNextHookEx调用钩子函数链中的下一个钩子函数。
SetWindowsHookEx Function
--------------------------------------------------------------------------------
The SetWindowsHookEx function installs an application-defined hook procedure into a hook chain. You would install a hook procedure to monitor the system for certain types of events. These events are associated either with a specific thread or with all threads in the same desktop as the calling thread.
Syntax
HHOOK SetWindowsHookEx( int idHook,
HOOKPROC lpfn,
HINSTANCE hMod,
DWORD dwThreadId
);
Parameters
idHook
[in] Specifies the type of hook procedure to be installed. This parameter can be one of the following values.
WH_CALLWNDPROC
Installs a hook procedure that monitors messages before the system sends them to the destination window procedure. For more information, see the CallWndProc hook procedure.
WH_CALLWNDPROCRET
Installs a hook procedure that monitors messages after they have been processed by the destination window procedure. For more information, see the CallWndRetProc hook procedure.
WH_CBT
Installs a hook procedure that receives notifications useful to a computer-based training (CBT) application. For more information, see the CBTProc hook procedure.
WH_DEBUG
Installs a hook procedure useful for debugging other hook procedures. For more information, see the DebugProc hook procedure.
WH_FOREGROUNDIDLE
Installs a hook procedure that will be called when the applications foreground thread is about to become idle. This hook is useful for performing low priority tasks during idle time. For more information, see the ForegroundIdleProc hook procedure.
WH_GETMESSAGE
Installs a hook procedure that monitors messages posted to a message queue. For more information, see the GetMsgProc hook procedure.
WH_JOURNALPLAYBACK
Installs a hook procedure that posts messages previously recorded by a WH_JOURNALRECORD hook procedure. For more information, see the JournalPlaybackProc hook procedure.
WH_JOURNALRECORD
Installs a hook procedure that records input messages posted to the system message queue. This hook is useful for recording macros. For more information, see the JournalRecordProc hook procedure.
WH_KEYBOARD
Installs a hook procedure that monitors keystroke messages. For more information, see the KeyboardProc hook procedure.
WH_KEYBOARD_LL
Windows NT/2000/XP: Installs a hook procedure that monitors low-level keyboard input events. For more information, see the LowLevelKeyboardProc hook procedure.
WH_MOUSE
Installs a hook procedure that monitors mouse messages. For more information, see the MouseProc hook procedure.
WH_MOUSE_LL
Windows NT/2000/XP: Installs a hook procedure that monitors low-level mouse input events. For more information, see the LowLevelMouseProc hook procedure.
WH_MSGFILTER
Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar. For more information, see the MessageProc hook procedure.
WH_SHELL
Installs a hook procedure that receives notifications useful to shell applications. For more information, see the ShellProc hook procedure.
WH_SYSMSGFILTER
Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar. The hook procedure monitors these messages for all applications in the same desktop as the calling thread. For more information, see the SysMsgProc hook procedure.
lpfn
[in] Pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process, the lpfn parameter must point to a hook procedure in a dynamic-link library (DLL). Otherwise, lpfn can point to a hook procedure in the code associated with the current process.
hMod
[in] Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.
dwThreadId
[in] Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread.
Return Value
If the function succeeds, the return value is the handle to the hook procedure.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
Remarks
An error may occur if the hMod parameter is NULL and the dwThreadId parameter is zero or specifies the identifier of a thread created by another process.
Calling the CallNextHookEx function to chain to the next hook procedure is optional, but it is highly recommended; otherwise, other applications that have installed hooks will not receive hook notifications and may behave incorrectly as a result. You should call CallNextHookEx unless you absolutely need to prevent the notification from being seen by other applications.
Before terminating, an application must call the UnhookWindowsHookEx function to free system resources associated with the hook.
The scope of a hook depends on the hook type. Some hooks can be set only with global scope; others can also be set for only a specific thread, as shown in the following table.
Hook Scope
WH_CALLWNDPROC Thread or global
WH_CALLWNDPROCRET Thread or global
WH_CBT Thread or global
WH_DEBUG Thread or global
WH_FOREGROUNDIDLE Thread or global
WH_GETMESSAGE Thread or global
WH_JOURNALPLAYBACK Global only
WH_JOURNALRECORD Global only
WH_KEYBOARD Thread or global
WH_KEYBOARD_LL Global only
WH_MOUSE Thread or global
WH_MOUSE_LL Global only
WH_MSGFILTER Thread or global
WH_SHELL Thread or global
WH_SYSMSGFILTER Global only
For a specified hook type, thread hooks are called first, then global hooks.
The global hooks are a shared resource, and installing one affects all applications in the same desktop as the calling thread. All global hook functions must be in libraries. Global hooks should be restricted to special-purpose applications or to use as a development aid during application debugging. Libraries that no longer need a hook should remove its hook procedure.
Windows 95/98/Me: SetWindowsHookEx is supported by the Microsoft® Layer for Unicode (MSLU). However, it does not make conversions. To see Unicode messages, notifications, and so forth, you must subclass the window. To use this version of the application programming interface (API), you must add certain files to your application, as outlined in Installing and Releasing Hook Procedures
那几个 API 我就不管了,说你说的 IE 按钮和工具栏。
IE 工具栏上的按钮的添加很简单,不一定要编程,改改注册表就可以了
IE 的历史/搜索/媒体等这样的“窗口”叫做 Band,要写 Band 用 VB 存在一定的困难,需要写成COM,并注册到 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Explorer Bars,详细的内容回头再说。
简单说说增加菜单和按钮,拿 flashget 做例子:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Extensions\{D6E814A0-E0C5-11d4-8D29-0050BA6940E3}]
"ButtonText"="FlashGet"
"Default Visible"="Yes"
"Exec"="D:\\play\\工具软件\\工具软件\\FLASHGET\\flashget.exe"
"HotIcon"="D:\\play\\工具软件\\工具软件\\FLASHGET\\flashget.exe,128"
"Icon"="D:\\play\\工具软件\\工具软件\\FLASHGET\\flashget.exe,223"
"CLSID"="{1FBA04EE-3024-11d2-8F1F-0000F87ABD16}"
"MenuStatusBar"="FlashGet"
"MenuText"="&FlashGet"
1、在 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Extensions
创建一个新的项,并用 genguid 生成一个 guid 作为名字,例如 flashget 的
{D6E814A0-E0C5-11d4-8D29-0050BA6940E3},你需要换一个不重复的哦
2、添加若干key,如 ButtonText MenuStatusBar 等描述信息
3、添加 Exec 指向你的执行程序
4、为它添加图表文件和激活图表文件 Icon 和 HotIcon
5、一定要创建一个 CLSID,值必须为"{1FBA04EE-3024-11d2-8F1F-0000F87ABD16}",这告诉 IE 它是一个menuitem
6、Flashget 没有这一项,你可以创建string类型的key,名为 MenuCustomize ,值为"help",如果有这个MenuCustomize且为"help",你新增的这一菜单项就跑到“帮助”菜单项下,否则是“工具”菜单项下。
好了,你可以修改 flashget 的注册表试试看效果——别忘记关掉IE,重新打开。
查查VC的头文件,你发现,在NT内核下,这两个钩子特别有用
WH_KEYBOARD_ll 实现全局键盘挂钩,不用dll
WH_MOUSE_ll 实现全局鼠标挂钩,不用dll