开发者

c# wpf show previous active window when closing current app

I have a c# wpf application I wrote that launches from an application that I didn't write (long story) and I want the focus to go back to the application that launches my app开发者_C百科lication when I close mine. Currently, if I have several applications maximized behind the one I launch my application launches from, when I close my application, one of the other applications will show instead of the one I launched from....if that makes sense.


You'll need to import these DLLs:

[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);

and put this is in you Window Closed event handler:

IntPtr iHandle = FindWindow(null, "title_bar_text_of_first_program");
if (iHandle != IntPtr.Zero) SetForegroundWindow(iHandle);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜