ShowWindow SW_MINIMIZE 无法恢复程序

发布于 2024-10-23 00:55:22 字数 771 浏览 5 评论 0原文

我有一个程序想要在后台启动,当我想稍后查看它时,可以单击快捷方式链接或可执行文件并让它调出我的应用程序。我已经让它在 Windows Mobile 模拟器中工作,但当我实际在设备上尝试它时,该应用程序最小化,但我无法将其恢复,除非我转到内置任务管理器程序并单击“切换到”。模拟器和设备都运行 WM 6.1.4。即使使用最小化控制框(“X”)进行智能最小化也会最小化应用程序,但当我单击 .exe 文件时,我无法恢复我的应用程序。

有什么想法吗?感谢您的帮助!

编辑:好的,所以我可能遗漏了一些关键信息。这是一个多线程程序。当我不启动线程而只是让主 UI 线程运行时,程序会最小化并恢复得很好。一旦我启动需要运行的后台线程,程序就会最小化,但不会恢复。对于这种情况,我是否需要使用 SW_MINIMIZE 以外的其他东西?

这是我最小化程序的代码:

private void HideForm()
{
    if (this.InvokeRequired)
    {
        HideFormCallback del = new HideFormCallback(HideForm);
        this.Invoke(del);
    }
    else
        ShowWindow(this.Handle, SW_MINIMIZE);
}

private const int SW_MINIMIZE = 6;

[DllImport("coredll.dll")]
private static extern bool ShowWindow(IntPtr wHnd, int cmdShow);

I have a program that I want to start up in the background and, when I want to view it later, be able to click the shortcut link or executable and have it bring up my application. I've gotten this to work in the Windows Mobile emulator but when I actually try it on a device, the app minimizes but I can't bring it back up unless I go to the built-in task manager program and click Switch To. Both the emulator and device are running WM 6.1.4. Even using the Minimize Control Box (the 'X') for smart minimization will minimize the app but I can't bring my app back up when I click on the .exe file.

Any thoughts? Appreciate the help!

EDIT: Okay, so I probably left out some key information. This is a multi-threaded program. When I don't start the threads and just let the main UI thread run, the program minimizes and restores just fine. As soon as I start the background threads I need to run, the program will minimize, but will not restore. Do I need to use something other than SW_MINIMIZE for this case?

Here's my code that minimizes the program:

private void HideForm()
{
    if (this.InvokeRequired)
    {
        HideFormCallback del = new HideFormCallback(HideForm);
        this.Invoke(del);
    }
    else
        ShowWindow(this.Handle, SW_MINIMIZE);
}

private const int SW_MINIMIZE = 6;

[DllImport("coredll.dll")]
private static extern bool ShowWindow(IntPtr wHnd, int cmdShow);

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

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

发布评论

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

评论(1

一刻暧昧 2024-10-30 00:55:22

好吧,我找到了答案。它实际上与单独的线程完全无关。看来我正在使用的 Intermec DLL 导致了这个问题。该设备是 Intermec CK3 扫描仪/手持式设备,在我的程序中,我尝试使用以下代码设置成像器照明设置:

Imager i = new Imager();
i.IllumLevel = 10;
i.Dispose();

我不知道 Imager 类是否被窃听并影响 WM 尝试恢复应用程序的方式或如果这是我调用它的方式,但注释掉这三行代码可以解决问题,所以我将进一步研究这个问题。

不管怎样,谢谢你们!

编辑:看起来上面的代码需要在 UI 线程上调用才能正确调用和处理。一旦我做了这个最小化和恢复工作就完美了。

Ok I found the answer. It actually had nothing to do with the separate thread at all. It seems an Intermec DLL I'm using is causing the issue. The device is an Intermec CK3 scanner/handheld and in my program I'm trying to set the imager illumination setting with the following code:

Imager i = new Imager();
i.IllumLevel = 10;
i.Dispose();

I don't know if the Imager class is bugged and affecting the way WM tries to restore the app or if it's the way I am calling it but commenting out these three lines of codes fixes the problem so I will look in to this further.

Thanks anyways though, guys!

EDIT: Looks like the code above needs to be invoked on the UI thread to be called and disposed correctly. Once I did this minimizing and restoring worked perfectly.

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