当DM应用程序窗口最小化时,如何处理由延迟任务发布的模式对话框?

迈克·昆德曼

当然,这是一个相当不可思议的问题,但实际上确实影响了我正在开发的DM脚本模块。我正在尝试使用自定义模式对话框来提醒用户注意由延迟的主线程任务检测到的错误情况。在大多数情况下,这工作得很好,但是如果在发布错误消息时恰好将DM应用程序窗口最小化,则当将DM应用程序窗口还原为前台应用程序时,它会以一种奇怪的状态结束。模态对话框是不可见的,但是它仍然禁止DM中的用户操作,直到通过“ enter”或“ esc”键将其关闭为止。

下面的示例代码演示了该问题,并提到了在GMS 1中有效的解决方案。

在GMS 2及更高版本中,是否存在类似或更好的解决方法?

class DeferredAlertTask
{
    Number deferredTaskID;

    DeferredAlertTask(Object self)
    {
        Number taskDelay_sec = 5;
        String message = "Click OK and then minimize the DM app window.\n";
        message += "After 5 seconds, select DM on the task bar to restore it.\n";
        message += "Dialog will be invisible, must hit 'enter' or 'esc' to go on.";
        OKDialog(message);

        deferredTaskID = AddMainThreadSingleTask(self, "Task", taskDelay_sec);
    }

    void Task(Object self)
    {
        String banner = "Error dialog";
        String message = "Error message details.";

        // Create the dialog box descriptor TagGroup
        TagGroup dialogItemsSpec;
        TagGroup dialogSpec = DLGCreateDialog(banner, dialogItemsSpec);

        // Create and add the content box and text field to the layout
        TagGroup contentBoxItemsSpec;
        TagGroup contentBoxSpec = DLGCreateBox(contentBoxItemsSpec);
        TagGroup contentLabelSpec = DLGCreateLabel(message);
        contentBoxItemsSpec.DLGAddElement(contentLabelSpec);
        dialogItemsSpec.DLGAddElement(contentBoxSpec);

        // If the DM app window has been minimized, 
        // this modal dialog will be invisible,
        // but it will still inhibit further user action
        // within DM as it awaits 'esc' or 'enter'.

        // The following is a remedy that works in GMS1, but not in GMS2
        // GetApplicationWindow().WindowSelect();

        Object dialog = Alloc(UIFrame).Init(dialogSpec);
        String result = (dialog.Pose()) ? "OK" : "Cancel";
        OKDialog(result);
    }
}

void main()
{
    Alloc(DeferredAlertTask);
}

main();
迈克·昆德曼

建议以LaunchExternalProcess()函数和外部程序为基础的解决方案提供了答案的途径。通过使用免费的开源Windows宏创建程序包AutoHotKey,我已经能够创建一个非常紧凑的名为RestoreDM.exe的可执行文件。通过将此可执行文件放置在可从DM脚本轻松访问的文件夹中,可以通过LaunchExternalProcessAsync()启动该可执行文件,以确保在发布自定义对话框之前恢复DM应用程序窗口。下面是原始测试脚本的修改版本,说明了此解决方案,并提供了有关AutoHotKey脚本的详细信息:

class DeferredAlertTask
{
    Number deferredTaskID;

    DeferredAlertTask(Object self)
    {
        Number taskDelay_sec = 5;
        String message = "Click OK and then minimize the DM app window.\n";
        message += "After 5 seconds, select DM on the task bar to restore it.\n";
        message += "Dialog will be invisible, must hit 'enter' or 'esc' to go on.";
        OKDialog(message);

        deferredTaskID = AddMainThreadSingleTask(self, "Task", taskDelay_sec);
    }

    void Task(Object self)
    {
        String banner = "Error dialog";
        String message = "Error message details.";

        // Create the dialog box descriptor TagGroup
        TagGroup dialogItemsSpec;
        TagGroup dialogSpec = DLGCreateDialog(banner, dialogItemsSpec);

        // Create and add the content box and text field to the layout
        TagGroup contentBoxItemsSpec;
        TagGroup contentBoxSpec = DLGCreateBox(contentBoxItemsSpec);
        TagGroup contentLabelSpec = DLGCreateLabel(message);
        contentBoxItemsSpec.DLGAddElement(contentLabelSpec);
        dialogItemsSpec.DLGAddElement(contentBoxSpec);

        // If the DM app window has been minimized, 
        // this modal dialog will be invisible,
        // but it will still inhibit further user action
        // within DM as it awaits 'esc' or 'enter'.

        // The following is a remedy that works in GMS1, but not in GMS2
        // GetApplicationWindow().WindowSelect();

        // For GMS2, we can use an executable that restores the DM app window.
        // The lines below launch RestoreDM.exe, placed in C:\ProgramData\Gatan,
        // where RestoreDM is an executable of the following AutoHotKey script:
        // IfWinNotActive, Digital Micrograph
        //      WinRestore, Digital Micrograph
        String commandDir = GetApplicationDirectory(3, 0);
        String restoreCommand = commandDir.PathConcatenate("RestoreDM");
        LaunchExternalProcessAsync(restoreCommand);
        Sleep(0.1);

        Object dialog = Alloc(UIFrame).Init(dialogSpec);
        String result = (dialog.Pose()) ? "OK" : "Cancel";
        OKDialog(result);
    }
}

void main()
{
    Alloc(DeferredAlertTask);
}

main();

必须使用异步变体LaunchExternalProcessAsync(),因为在主线程上调用了延迟警报任务,因此当RestoreDM程序提示时(导致DM挂起),阻止DM还原其窗口。还要注意的是,在调用外部程序之后需要短暂的睡眠,以确保在创建自定义对话框之前恢复DM应用程序窗口。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

当对话框的ShowInTaskBar = false时,如何通过任务栏关闭应用程序或模式对话框?

来自分类Dev

当对话框的ShowInTaskBar = false时,如何通过任务栏关闭应用程序或模式对话框?

来自分类Dev

为什么创建对话框时Swing应用程序最小化?

来自分类Dev

我无法安装应用程序,因为我不知道如何处理身份验证对话框

来自分类Dev

如何在父窗口中从iframe(共享点托管的应用程序,(应用程序部分))打开模式对话框弹出窗口

来自分类Dev

如何处理模式对话框的保存事件

来自分类Dev

如何从对话中最小化或关闭应用程序?

来自分类Dev

在Android上将Chrome最小化时,Web应用程序可以执行任务吗?

来自分类Dev

获取对话框窗口处理程序

来自分类Dev

最小化或折叠Bootstrap 2.3.2模式对话框?

来自分类Dev

如何使用Qt中的框架创建透明的非模式对话框,该框架包含在主应用程序窗口中并且可以包含QPushButtons

来自分类Dev

该应用程序应如何处理延迟的SKPaymentTransaction?

来自分类Dev

如何从终端打开“运行应用程序”对话框?

来自分类Dev

dlg.DoModal()使对话框成为应用程序的模式,而不是前一个对话框的模式

来自分类Dev

最小化和恢复应用程序时如何处理网络呼叫错误-Windows Phone 8

来自分类Dev

Qt最小化对话框最小化父窗口

来自分类Dev

我的应用程序在最小化时重置数据

来自分类Dev

如何在我的应用程序级别始终使对话框窗口始终位于最前面

来自分类Dev

如何检测JavaFx应用程序窗口处于打开状态并在其中显示对话框?

来自分类Dev

Selenium:如何处理基于重定向数显示的模式对话框

来自分类Dev

如何处理scala.js引导模式对话框中的数据输入?

来自分类Dev

关闭对话框窗口的 DM 脚本

来自分类Dev

Python Tkinter:当主应用程序最小化时,进度条不会最小化

来自分类Dev

如果手机在关闭应用程序时收到通知,如何触发“弹出窗口,对话框,应用程序栏或其他嵌入式元素”?

来自分类Dev

首次启动应用程序时,对话框窗口将打开

来自分类Dev

对话框抛出“无法添加窗口-令牌null不适用于应用程序”

来自分类Dev

Win32 API:打开对话框窗口后,应用程序冻结

来自分类Dev

在没有主应用程序窗口的屏幕上显示的Photoshop对话框

来自分类Dev

MFC应用程序:从窗体按钮启动一个(模式)对话框

Related 相关文章

  1. 1

    当对话框的ShowInTaskBar = false时,如何通过任务栏关闭应用程序或模式对话框?

  2. 2

    当对话框的ShowInTaskBar = false时,如何通过任务栏关闭应用程序或模式对话框?

  3. 3

    为什么创建对话框时Swing应用程序最小化?

  4. 4

    我无法安装应用程序,因为我不知道如何处理身份验证对话框

  5. 5

    如何在父窗口中从iframe(共享点托管的应用程序,(应用程序部分))打开模式对话框弹出窗口

  6. 6

    如何处理模式对话框的保存事件

  7. 7

    如何从对话中最小化或关闭应用程序?

  8. 8

    在Android上将Chrome最小化时,Web应用程序可以执行任务吗?

  9. 9

    获取对话框窗口处理程序

  10. 10

    最小化或折叠Bootstrap 2.3.2模式对话框?

  11. 11

    如何使用Qt中的框架创建透明的非模式对话框,该框架包含在主应用程序窗口中并且可以包含QPushButtons

  12. 12

    该应用程序应如何处理延迟的SKPaymentTransaction?

  13. 13

    如何从终端打开“运行应用程序”对话框?

  14. 14

    dlg.DoModal()使对话框成为应用程序的模式,而不是前一个对话框的模式

  15. 15

    最小化和恢复应用程序时如何处理网络呼叫错误-Windows Phone 8

  16. 16

    Qt最小化对话框最小化父窗口

  17. 17

    我的应用程序在最小化时重置数据

  18. 18

    如何在我的应用程序级别始终使对话框窗口始终位于最前面

  19. 19

    如何检测JavaFx应用程序窗口处于打开状态并在其中显示对话框?

  20. 20

    Selenium:如何处理基于重定向数显示的模式对话框

  21. 21

    如何处理scala.js引导模式对话框中的数据输入?

  22. 22

    关闭对话框窗口的 DM 脚本

  23. 23

    Python Tkinter:当主应用程序最小化时,进度条不会最小化

  24. 24

    如果手机在关闭应用程序时收到通知,如何触发“弹出窗口,对话框,应用程序栏或其他嵌入式元素”?

  25. 25

    首次启动应用程序时,对话框窗口将打开

  26. 26

    对话框抛出“无法添加窗口-令牌null不适用于应用程序”

  27. 27

    Win32 API:打开对话框窗口后,应用程序冻结

  28. 28

    在没有主应用程序窗口的屏幕上显示的Photoshop对话框

  29. 29

    MFC应用程序:从窗体按钮启动一个(模式)对话框

热门标签

归档