Mirror

Launch a Windows open file dialog without using the standard Delphi dialog component (Views: 103)


Problem/Question/Abstract:

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:

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:

procedure TForm1.OpenApiClick(Sender: TObject);
var
  OpenFile: TOpenFileName;
begin
  with OpenFile do
  begin
    lStructSize := SizeOf(TOpenFilename);
    hInstance := SysInit.HInstance;
    hWndOwner := {Application.} Handle;
    lpstrFilter := 'Text Files (*.txt)' + Chr(0) + '*.txt' + Chr(0) +
                'All Files (*.*)' + Chr(0) + '*.*' + Chr(0);
    nFilterIndex := 1;
    {create a buffer for the file}
    nMaxFile := 255;
    lpstrFile := PChar(StringOfChar(' ', nMaxFile - 1));
    {create a buffer for the file title}
    nMaxFileTitle := 255;
    lpstrFileTitle := PChar(StringOfChar(' ', nMaxFileTitle - 1));
    {set the initial directory}
    lpstrInitialDir := 'C:\';
    lpstrTitle := 'Open a file, please';
    Flags := OFN_EXPLORER;
  end;
  if not GetOpenFileName(OpenFile) then
    Exit;
end;

<< Back to main page