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

你说的曾经没有我的故事 提交于 2019-12-10 14:49:21

问题


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.


回答1:


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).




回答2:


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!



来源:https://stackoverflow.com/questions/9411840/how-can-i-use-futurewindows-with-standard-file-open-dialogs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!