开发者

ShowWindow SW_MINIMIZE can't restore program

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 runnin开发者_JAVA百科g 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);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜