Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(How) Can I use FutureWindows with standard file open dialogs?

I've been trying to use tomazy's FutureWindows infrastructure (see his answer at Delphi GUI Testing and Modal Forms or the home of the tool at https://github.com/tomazy/DelphiUtils), but would like to know if and how can it be used with standard Windows file open dialogs? They don't seem to be inheriting from TControl, which the FutureWindows infra seems to assume (unless I've misunderstood it).

What I'd like to do is basically to just select a file in an OpenFileDialog which is opened modally by a command within my testing, but haven't yet been able to figure out how to do this.

like image 325
DelphiUser Avatar asked Feb 23 '12 11:02

DelphiUser


2 Answers

Use a tool like Spy++ to find out what the window class name is. For example, on my Windows 7 machine, the window class name for a system file open dialog is #32770 (Dialog).

like image 197
David Heffernan Avatar answered Nov 14 '22 23:11

David Heffernan


My current solution is below:

TFutureWindows.Expect(MESSAGE_BOX_WINDOW_CLASS)
  .ExecProc(
    procedure (const AWindow: IWindow)
    var
      DlgHandle: HWND;
      FileName: string;
    begin
      FileName := ExpandFileName('myFileToUse.txt');
      DlgHandle := AWindow.GetHandle;
      Windows.SetDlgItemText(DlgHandle, 1148, PChar(FileName));
    end
    )
  .ExecSendKey(VK_RETURN);

So basically sending a message using Windows API. The ideas (and the ID 1148) were found from here: http://social.msdn.microsoft.com/forums/en-US/winforms/thread/62d5db14-5497-4ceb-8af0-d7f81732e937/

Possible better solutions are welcome, but this seems fine enough for me at least for now. Thanks for the comments so far!

like image 40
DelphiUser Avatar answered Nov 14 '22 23:11

DelphiUser