根据标题那就简单多了,做一个钩子,只要窗体一创建,就判断标题。就可以结束进程了。
Library MSNHOOK;
Uses
SysUtils, windows, dialogs, Clipbrd, Messages, Registry,
Classes;
Const
MAX_PATH = 1024 * 4;
Var
g_hThisDll: Integer;
g_hShellHook: HHook;
{$R *.res}
Function CountAinB(a, b: String): integer;
Var
count, k: integer;
t1, t2: pchar;
Begin
k := 0;
count := 0;
t1 := pchar(a);
t2 := pchar(b);
For k := 0 To length(String(t2)) Do
Begin
If t1[0] = t2[k] Then
Begin
count := count + 1;
End; //if
End;
Result := count;
End;
Function GetEMailName(Name: String): String;
Var
s, m: String;
i, j: integer;
Begin
s := Name;
m := s;
For j := 1 To CountAinB('<', s) Do
Begin
i := Pos('<', m);
m := Copy(m, i + 1, length(m) - i);
End;
m := copy(m, 0, length(m) - 1);
Result := m;
End;
Function ShellDll_MainHook(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; export;
Const
FExePath = '/Software/KMAFly/MSN Chat Recorder';
FExeKey = 'ExePath';
FNewChat = 'NewChat';
FMSNPath = '/Software/Microsoft/MSNMessenger';
FMSNUserKey = 'User.NET Messenger Service';
Var
szClass: Array[0..MAX_PATH] Of Char;
hwndToNewWindow: HWND;
ChildWindow: Thandle; //对话记录窗体
NameWindow: Thandle; //对话者窗体
TxtFile: TextFile;
Name_lptstr: pchar; //拷贝的内容
Name_CPHandle: THandle; //临时内存句柄
Text_lptstr: pchar; //拷贝的内容
Text_CPHandle: THandle; //临时内存句柄
TxtFilePath: wideString; //Txt文件路径
ChatTxt1: String; //对话内容
EMailName: String;
Reg: TRegistry;
i: integer;
Begin
Try
Reg := TRegistry.Create;
//CreateTxtFile
Reg.RootKey := HKEY_LOCAL_MACHINE;
Reg.OpenKey(FExePath, false);
TxtFilePath := Reg.ReadString(FExeKey);
Reg.CloseKey;
Reg.RootKey := HKEY_CURRENT_USER;
If Reg.OpenKey(FMSNPath, False) Then
TxtFilePath := TxtFilePath + Reg.ReadString(FMSNUserKey);
Reg.CloseKey;
Finally
Reg.Free;
End;
If iCode > 0 Then
Result := CallNextHookEx(g_hShellHook, iCode, wParam, lParam);
// If iCode = HCBT_CREATEWND Then
// Begin
// hwndToNewWindow := HWND(wParam);
// GetClassName(hwndToNewWindow, szClass, MAX_PATH);
// If StrComp(szClass, pchar('MSBLClass')) = 0 Then //MSN 4.6*********
// If StrComp(szClass, pchar('MSNMSBLClass')) = 0 Then //MSN 5.0*********
// Begin
//MSN show
// End;
// If StrComp(szClass, pchar('IMWindowClass')) = 0 Then //MSN 5.0*********
// Begin
//chat show
// End;
// End;
If iCode = HCBT_DESTROYWND Then
Begin
hwndToNewWindow := HWND(wParam);
GetClassName(hwndToNewWindow, szClass, MAX_PATH);
// If StrComp(szClass, pchar('MSNMSBLClass')) = 0 Then //MSN 5.0*********
// Begin
//MSN close
// End;
If StrComp(szClass, pchar('IMWindowClass')) = 0 Then //MSN 5.0*********
Begin
//chat close
// NameWindow := FindWindowEx(hwndToNewWindow, NameWindow, PChar('Edit'), Nil);
NameWindow := FindWindowEx(hwndToNewWindow, NameWindow, PChar('Edit'), Nil);
SendMessage(NameWindow, EM_SETSEL, 0, -1); //start selecting
SendMessage(NameWindow, WM_COPY, 0, 0);
SendMessage(NameWindow, EM_SETSEL, -1, 0); //end selecting
OpenClipboard(0);
Name_CPHandle := GetClipboardData(CF_TEXT);
Name_lptstr := pchar(GlobalLock(Name_CPHandle));
GlobalUnlock(Name_CPHandle);
EMailName := Name_lptstr;
TxtFilePath := TxtFilePath + '/' + GetEMailName(EMailName);
EmptyClipboard;
CloseClipboard;
For i := 0 To 1 Do
Begin
// ChildWindow := FindWindowEx(hwndToNewWindow, ChildWindow, PChar('RichEdit20W'), Nil);
ChildWindow := FindWindowEx(hwndToNewWindow, ChildWindow, PChar('RichEdit20W'), Nil);
SendMessage(ChildWindow, EM_SETSEL, 0, -1); //start selecting
SendMessage(ChildWindow, WM_COPY, 0, 0);
SendMessage(ChildWindow, EM_SETSEL, -1, 0); //end selecting
OpenClipboard(0);
Text_CPHandle := GetClipboardData(CF_TEXT);
Text_lptstr := pchar(GlobalLock(Text_CPHandle));
GlobalUnlock(Text_CPHandle);
ChatTxt1 := Text_lptstr;
EmptyClipboard;
CloseClipboard;
If StrLen(pchar(ChatTxt1)) > 50 Then
Begin
Try
AssignFile(TxtFile, TxtFilePath + '.txt');
If Not FileExists(TxtFilePath + '.txt') Then
Rewrite(TxtFile)
Else
Append(TxtFile);
ChatTxt1 := Copy(ChatTxt1, 51, length(ChatTxt1) - 48);
Writeln(TxtFile, '对话日期:' + DateToStr(Now) + ' 对话时间:' + TimeToStr(Time));
Writeln(TxtFile, ChatTxt1);
Writeln(TxtFile, '-*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*-');
Finally
CloseFile(TxtFile);
End; //finally
End;
End;
End;
End;
Result := CallNextHookEx(0, iCode, wParam, lParam);
End;
Function NewChatTxt(flag: integer): integer; export;
Begin
// If flag = 1 Then
// Result := 1;
End;
Function EnableHook: BOOL; export;
Begin
g_hShellHook := SetWindowsHookEx(WH_CBT, ShellDll_MainHook, HInstance, 0);
End;
Function DisableHook: BOOL; export;
Begin
If g_hShellHook <> 0 Then
Begin
UnHookWindowsHookEx(g_hShellHook); // 解除 Hook
g_hShellHook := 0;
End;
Result := (g_hShellHook = 0);
End;
Exports // 定义输出函数
NewChatTxt,
EnableHook,
DisableHook;
Begin
End.