我在button中,写this.hide(),使得用户点击button时,软件能运行在后台,请问怎么能提供一种方法,让用户能使得它再运行到前台来?
我测试了再次双击程序的快捷方式,发现如果是执行过this.hide()的不行,如果是用 点击窗口右上角的“X”来退到后台的,可以通过再次双击快捷方式回到前台。
------解决方案--------------------
常用的方法:
当程序重入的时候,我们可以知道,例如使用CreateMutex等等;这个时候你调用ShowWindow或者SetForegroundWindow
将窗口提到最前
------解决方案--------------------
在程序最开始处用这个,然后重新运行程序就好了。
hWnd = FindWindow(程序类名, 程序主窗口名);
if (hWnd)
{
// set focus to foremost child window
// The "| 0x00000001" is used to bring any owned windows to the foreground and
// activate them.
SetForegroundWindow((HWND)((ULONG)hWnd | 0x00000001));
return 0;
}
------解决方案--------------------
FindWindow(程序类名, 程序主窗口名);
SetForegroundWindow((HWND)((ULONG)hWnd ¦ 0x00000001));
------解决方案--------------------
c#
[DllImport("user32.dll")] private static extern
bool SetForegroundWindow(IntPtr hWnd);