钩子函数里的 HC_SYSMODALOFF 是什么意思,delphi没有相关帮助(10分)

  • 主题发起人 主题发起人 seeyouknowme
  • 开始时间 开始时间
S

seeyouknowme

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;<br><br>interface<br><br>uses<br>Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>StdCtrls;<br><br>type<br>TForm1 = class(TForm)<br>Button1: TButton;<br>Button2: TButton;<br>Button3: TButton;<br>Edit1: TEdit;<br>Button4: TButton;<br>procedure FormCreate(Sender: TObject);<br>procedure Button1Click(Sender: TObject);<br>procedure Button2Click(Sender: TObject);<br>procedure Button3Click(Sender: TObject);<br>private<br>{ Private declarations }<br>public<br>{ Public declarations }<br>end;<br><br>var<br>Form1: TForm1;<br><br>EventArr:array[0..1000]of EVENTMSG;<br>EventLog:Integer;<br>PlayLog:Integer;<br>hHook,hPlay:Integer;<br>recOK:Integer;<br>canPlay:Integer;<br>bDelay:Bool;<br>implementation<br>{typedef struct tagEVENTMSG { &nbsp; &nbsp;// em &nbsp;<br>&nbsp; &nbsp; UINT &nbsp;message;<br>&nbsp; &nbsp; UINT &nbsp;paramL;<br>&nbsp; &nbsp; UINT &nbsp;paramH;<br>&nbsp; &nbsp; DWORD time;<br>&nbsp; &nbsp; HWND &nbsp;hwnd;<br>}// EVENTMSG;}<br><br>{$R *.DFM}<br>Function PlayProc(iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;<br>begin<br>canPlay:=1;<br>Result:=0;<br><br>if iCode &lt; 0 then //必须将消息传递到消息链的下一个接受单元<br>&nbsp; &nbsp;Result := CallNextHookEx(hPlay,iCode,wParam,lParam)<br>else if iCode = HC_SYSMODALON then<br>&nbsp; &nbsp;canPlay:=0<br>else if iCode = HC_SYSMODALOFF then<br>&nbsp; &nbsp;canPlay:=1<br>else if ((canPlay =1 )and(iCode=HC_GETNEXT)) then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;if bDelay then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bDelay:=False;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result:=50;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; pEventMSG(lParam)^:=EventArr[PlayLog];<br>&nbsp; &nbsp; end<br>else if ((canPlay = 1)and(iCode = HC_SKIP))then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; bDelay := True;<br>&nbsp; &nbsp; &nbsp; PlayLog:=PlayLog+1;<br>&nbsp; &nbsp; end;<br>if PlayLog&gt;=EventLog then<br><br>&nbsp; &nbsp; UNHookWindowsHookEx(hPlay);<br><br>end;<br><br>function HookProc(iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;<br>begin<br>&nbsp; &nbsp; recOK:=1;<br>&nbsp; &nbsp; Result:=0;<br><br>&nbsp; &nbsp; if iCode &lt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := CallNextHookEx(hHook,iCode,wParam,lParam) &nbsp; &nbsp; //执行当前钩子,<br>&nbsp; &nbsp; else if iCode = HC_SYSMODALON then<br>&nbsp; &nbsp; &nbsp; &nbsp; recOK:=0<br>&nbsp; &nbsp; else if iCode = HC_SYSMODALOFF then<br>&nbsp; &nbsp; &nbsp; &nbsp; recOK:=1<br>&nbsp; &nbsp; else if ((recOK&gt;0) and (iCode = HC_ACTION)) then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; EventArr[EventLog]:=pEventMSG(lParam)^;<br>&nbsp; &nbsp; &nbsp; &nbsp; EventLog:=EventLog+1;<br>&nbsp; &nbsp; &nbsp; &nbsp; if EventLog &gt;=1000 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UnHookWindowsHookEx(hHook);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; &nbsp; Button1.Caption:='纪录';<br>&nbsp; &nbsp; Button2.Caption:='停止';<br>&nbsp; &nbsp; Button3.Caption:='回放';<br>&nbsp; &nbsp; Button4.Caption:='范例';<br>&nbsp; &nbsp; //Button2.Enabled:=False;<br>&nbsp; &nbsp; //Button3.Enabled:=False;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; &nbsp; EventLog:=0;<br>&nbsp; &nbsp; //建立键盘鼠标操作消息纪录链<br>&nbsp; &nbsp; hHook:=SetwindowsHookEx(WH_JOURNALRECORD,HookProc,HInstance,0);<br>&nbsp; &nbsp; Button2.Enabled:=True;<br>&nbsp; &nbsp; Button1.Enabled:=False;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp; &nbsp; &nbsp; UnHookWindowsHookEx(hHook); &nbsp; //停止 释放钩子<br>&nbsp; &nbsp; &nbsp; hHook:=0; //<br>&nbsp; &nbsp; &nbsp; Button1.Enabled:=True;<br>&nbsp; &nbsp; &nbsp; Button2.Enabled:=False;<br>&nbsp; &nbsp; &nbsp; Button3.Enabled:=True;<br>end;<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>begin<br>PlayLog:=0;<br>//建立键盘鼠标操作消息纪录回放链<br>hPlay:=SetwindowsHookEx(WH_JOURNALPLAYBACK,PlayProc,HInstance,0);<br>Button3.Enabled:=False;<br>{HHOOK SetWindowsHookEx(<br><br>&nbsp; &nbsp; int idHook, // type of hook to install &nbsp;钩子类型 比如这里的WH_journalplayback,就是回放存储的信息过程<br>&nbsp; &nbsp; HOOKPROC lpfn, // address of hook procedure &nbsp; &nbsp; 钩子处理过程,hookProc 是一个回调过程,需要自己写,这里是指playpro过程<br>&nbsp; &nbsp; HINSTANCE hMod, // handle of application instance &nbsp; &nbsp; &nbsp;实例句柄。DefHookProc<br>&nbsp; &nbsp; DWORD dwThreadId // identity of thread to install hook for<br>&nbsp; &nbsp;);}<br>end;<br><br>end.<br>
 
The JournalPlaybackProc hook procedure is a callback function that inserts mouse and keyboard messages into the system message queue. Typically, an application uses this hook procedure to play back a series of mouse and keyboard messages recorded previously by the JournalRecordProc hook procedure. As long as a JournalPlaybackProc hook procedure is installed, regular mouse and keyboard input is disabled. <br><br>LRESULT CALLBACK JournalPlaybackProc(<br><br>&nbsp; &nbsp; int code, // hook code<br>&nbsp; &nbsp; WPARAM wParam, // undefined<br>&nbsp; &nbsp; LPARAM lParam // address of message being processed<br>&nbsp; &nbsp;); <br>&nbsp;<br><br>Parameters<br><br>code<br><br>Specifies a code the hook procedure uses to determine how to process the message. This parameter can be one of the following values: <br><br>Value Meaning<br>HC_GETNEXT The hook procedure must copy the current mouse or keyboard message to the EVENTMSG structure pointed to by the lParam parameter. <br>HC_NOREMOVE An application has called the PeekMessage function with wRemoveMsg set to PM_NOREMOVE, indicating that the message is not removed from the message queue after PeekMessage processing. <br>HC_SKIP The hook procedure must prepare to copy the next mouse or keyboard message to the EVENTMSG structure pointed to by lParam. Upon receiving the HC_GETNEXT code, the hook procedure must copy the message to the structure. &nbsp;<br>HC_SYSMODALOFF A system-modal dialog box has been destroyed. The hook procedure must resume playing back the messages.<br>HC_SYSMODALON A system-modal dialog box is being displayed. Until the dialog box is destroyed, the hook procedure must stop playing back messages.<br>&nbsp;<br><br>If code is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and should return the value returned by CallNextHookEx. <br><br>wParam<br><br>Specifies a NULL value. <br><br>lParam<br><br>Points to an EVENTMSG structure that represents a message being processed by the hook procedure. This parameter is valid only when the code parameter is HC_GETNEXT. <br><br>&nbsp;<br><br>Return Values<br><br>To have the system wait before processing the message, the return value must be the amount of time, in clock ticks, that the system should wait. (This value can be computed by calculating the difference between the time members in the current and previous input messages.) To process the message immediately, the return value should be zero. The return value is used only if the hook code is HC_GETNEXT; otherwise, it is ignored. <br><br>Remarks<br><br>A JournalPlaybackProc hook procedure should copy an input message to the lParam parameter. The message must have been previously recorded by using a JournalRecordProc hook procedure, which should not modify the message. <br>To retrieve the same message over and over, the hook procedure can be called several times with the <br>code parameter set to HC_GETNEXT without an intervening call with code set to HC_SKIP. <br>If code is HC_GETNEXT and the return value is greater than zero, the system sleeps for the number of milliseconds specified by the return value. When the system continues, it calls the hook procedure again with code set to HC_GETNEXT to retrieve the same message. The return value from this new call to JournalPlaybackProc should be zero; otherwise, the system will go back to sleep for the number of milliseconds specified by the return value, call JournalPlaybackProc again, and so on. The system will appear to be hung. <br><br>Unlike most other global hook procedures, the JournalRecordProc and JournalPlaybackProc hook procedures are always called in the context of the thread that set the hook. <br>After the hook procedure returns control to the system, the message continues to be processed. If code<br>&nbsp;is HC_SKIP, the hook procedure must prepare to return the next recorded event message on its next call. <br>An application installs a JournalPlaybackProc hook procedure by specifying the WH_JOURNALPLAYBACK hook type and the address of the hook procedure in a call to the SetWindowsHookEx function. <br><br>A Win32 JournalRecordProc hook procedure does not need to live in a dynamic-link library. A Win32 JournalRecordProc hook procedure can live in the application itself. <br>If the user presses CTRL+ESC or CTRL+ALT+DEL during journal playback, the system stops the playback, unhooks the journal playback procedure, and posts a WM_CANCELJOURNAL message to the journaling application. <br>If the hook procedure returns a message in the range WM_KEYFIRST to WM_KEYLAST, the following conditions apply:<br><br>?The paramL member of the EVENTMSG structure specifies the virtual key code of the key that was pressed.<br>?The paramH member of the EVENTMSG structure specifies the scan code.<br>?There's no way to specify a repeast count. The event is always taken to represent one key event.<br><br>JournalPlaybackProc is a placeholder for an application-defined or library-defined function name.
 
这些帮助我都看过了,关键是这些<br>if iCode &lt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp;Result := CallNextHookEx(hHook,iCode,wParam,lParam) &nbsp; &nbsp; <br>&nbsp; &nbsp;else if iCode = HC_SYSMODALON then<br>&nbsp; &nbsp; &nbsp; &nbsp;recOK:=0<br>&nbsp; &nbsp;else if iCode = HC_SYSMODALOFF then<br>&nbsp; &nbsp; &nbsp; &nbsp;recOK:=1<br>&nbsp; &nbsp;else if ((recOK&gt;0) and (iCode = HC_ACTION)) then<br>.....<br>这里的icode的类型是指什么,<br>也就是HC_SYSMODALON,HC_SYSMODALOFF &nbsp;,HC_ACTION<br>指的是什么类型的东西,这些类型还有那些,分别是什么<br><br><br>function HookProc(iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;<br>begin<br>&nbsp; &nbsp;recOK:=1;<br>&nbsp; &nbsp;Result:=0;<br><br>&nbsp; &nbsp;if iCode &lt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp;Result := CallNextHookEx(hHook,iCode,wParam,lParam) &nbsp; &nbsp; //执行当前钩子,<br>&nbsp; &nbsp;else if iCode = HC_SYSMODALON then<br>&nbsp; &nbsp; &nbsp; &nbsp;recOK:=0<br>&nbsp; &nbsp;else if iCode = HC_SYSMODALOFF then<br>&nbsp; &nbsp; &nbsp; &nbsp;recOK:=1<br>&nbsp; &nbsp;else if ((recOK&gt;0) and (iCode = HC_ACTION)) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;EventArr[EventLog]:=pEventMSG(lParam)^;<br>&nbsp; &nbsp; &nbsp; &nbsp;EventLog:=EventLog+1;<br>&nbsp; &nbsp; &nbsp; &nbsp;if EventLog &gt;=1000 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;UnHookWindowsHookEx(hHook);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp;end;<br>end;<br><br>
 
后退
顶部