Ok, it worked, but now I'm trying to hook the FileOpenDialog for the whole system:
Dll-Code:
Code: Select all
library DllHook;
uses
SysUtils, Classes, CommDlg, madCodeHook, Windows, Messages;
const
FCIDM_SHVIEW_LARGEICON = 28713;
FCIDM_SHVIEW_SMALLICON = 28714;
FCIDM_SHVIEW_LIST = 28715;
FCIDM_SHVIEW_REPORT = 28716;
FCIDM_SHVIEW_THUMBNAIL = 28717; // XP only
FCIDM_SHVIEW_TILE = 28718; // XP
var GetOpenFileNameOld : function(var OpenFile: tagOFNA): longbool; stdcall;
function Hook(Wnd: HWND; Msg: Cardinal; wParam: Integer; lParam: Integer): Cardinal; stdcall;
var
Ctrl: HWND;
Parent: HWND;
begin
if Msg = WM_SHOWWINDOW then
begin
Parent := GetParent(Wnd);
Ctrl := FindWindowEx(Parent, 0, PChar('SHELLDLL_DefView'), nil);
if Ctrl <> 0 then
SendMessage(Ctrl, WM_COMMAND, FCIDM_SHVIEW_THUMBNAIL, 0);
end;
Result := 0;
// PostMessage(Wnd, WM_USER, GetParent(Wnd), 0);
end;
function GetOpenFileNameCallback(var OpenFile: tagOFNA) : longbool; stdcall;
begin
OpenFile.lpfnHook := Hook;
OpenFile.Flags := OpenFile.Flags or OFN_ENABLEHOOK or OFN_EXPLORER;
OpenFile.lpstrTitle := 'Ein gehookter FileOpenDialog!';
Result := GetOpenFileNameOld(OpenFile);
end;
begin
HookAPI('comdlg32.dll', 'GetOpenFileNameA',
@GetOpenFileNameCallback, @GetOpenFileNameOld);
end.
ApplicationCode:
Code: Select all
unit frDllHook;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
CommDlg, madCodeHook;
procedure TForm1.Button1Click(Sender: TObject);
begin
OpenDialog1.Execute;
end;
initialization
// if not HookAPI('comdlg32.dll', 'GetOpenFileNameA',
// @GetOpenFileNameCallback, @GetOpenFileNameOld, ) then
// ShowMessage('Fehler beim Hook von GetOpenFileName!');
if not InjectLibrary((ALL_SESSIONS or SYSTEM_PROCESSES), 'DllHook.dll') then
ShowMessage('Fehler beim Inject von DllHook.dll');
finalization
// UnHookAPI(@GetOpenFileNameOld);
UnInjectLibrary((ALL_SESSIONS or SYSTEM_PROCESSES), 'DllHook.dll');
end.
But it only seems to work for my Application but not for others, i.e. I tried to open a file from the notepad, but the FileOpenDialog did not change.