(如何)我可以使用带有标准文件打开对话框的 FutureWindows 吗?

发布于 2025-01-08 19:51:08 字数 475 浏览 0 评论 0 原文

我一直在尝试使用 tomazy 的 FutureWindows 基础设施(请参阅他的答案 Delphi GUI 测试和模态表单 或工具主页 https://github.com/tomazy/DelphiUtils),但想知道它是否以及如何与标准 Windows 文件打开对话框一起使用?它们似乎没有继承自 TControl,而 FutureWindows 基础结构似乎假设了这一点(除非我误解了它)。

我想做的基本上只是在 OpenFileDialog 中选择一个文件,该文件是通过我的测试中的命令以模式方式打开的,但尚未弄清楚如何执行此操作。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小巷里的女流氓 2025-01-15 19:51:08

使用诸如 Spy++ 之类的工具来查找窗口类名称。例如,在我的 Windows 7 计算机上,系统文件打开对话框的窗口类名称是 #32770 (Dialog)

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

⊕婉儿 2025-01-15 19:51:08

我当前的解决方案如下:

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

所以基本上使用 Windows API 发送消息。这些想法(和ID 1148)可以从这里找到:http://social.msdn.microsoft.com/forums/en-US/winforms/thread/62d5db14-5497-4ceb-8af0-d7f81732e937/

欢迎可能的更好的解决方案,但这至少现在对我来说似乎足够了。
感谢到目前为止的评论!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文