我在尝试将我的应用程序窗口置于最前面(即在所有其他窗口之上)时遇到了麻烦。我希望用户能够双击系统托盘中的 notifyIcon,并且如果应用程序已经打开了一个窗口,可以将其购买到前面。我曾尝试使用以下两个 P/inovkes,但似乎都无法始终如一地工作。有人知道如何将窗户放在前面/顶部吗?
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
tatic extern bool SetForegroundWindow(IntPtr hWnd);
ShowWindowAsync(ADProcess.MainWindowHandle, SW_RESTORE);
SetForegroundWindow(ADProcess.MainWindowHandle);