Author: Jonas Bilinkevicius
Is there an API call or other to launch a Windows open file dialog without using
the standard delphi dialog component? I call a function "Hooklock1" from:
1 2 keyHook := SetWindowsHookEx(WH_KEYBOARD, HookLock1, HInstance, 0);
In this function no references to delphi global variables or components seem to
work, I need to call an open dialog box to specify a filename. Any ideas?
Answer:
3 4 procedure TForm1.OpenApiClick(Sender: TObject);
5 var6 OpenFile: TOpenFileName;
7 begin8 with OpenFile do9 begin10 lStructSize := SizeOf(TOpenFilename);
11 hInstance := SysInit.HInstance;
12 hWndOwner := {Application.} Handle;
13 lpstrFilter := 'Text Files (*.txt)' + Chr(0) + '*.txt' + Chr(0) +
14 'All Files (*.*)' + Chr(0) + '*.*' + Chr(0);
15 nFilterIndex := 1;
16 {create a buffer for the file}17 nMaxFile := 255;
18 lpstrFile := PChar(StringOfChar(' ', nMaxFile - 1));
19 {create a buffer for the file title}20 nMaxFileTitle := 255;
21 lpstrFileTitle := PChar(StringOfChar(' ', nMaxFileTitle - 1));
22 {set the initial directory}23 lpstrInitialDir := 'C:\';
24 lpstrTitle := 'Open a file, please';
25 Flags := OFN_EXPLORER;
26 end;
27 ifnot GetOpenFileName(OpenFile) then28 Exit;
29 end;