専用フォームを実行し、最もフロントワンクリックで表示
とが見つかりました
SetForegroundWindowない安定した効果的な
最後に、使用SetWindowPos
コードを貼り付けます。
-
public
const
int HWND_TOPMOST =
-1;
-
public
const
int HWND_NOTOPMOST =
-2;
-
protected override void OnStartup(StartupEventArgs e)
-
{
-
-
bool isNewInstance;
-
base.OnStartup(e);
-
Mutex mutex =
new Mutex(
true,
"Single",
out isNewInstance);
-
if (isNewInstance !=
true)
-
{
-
IntPtr intPtr = FindWindowW(
null,
"Single");
-
if (intPtr != IntPtr.Zero)
-
{
-
-
-
SetWindowPos(intPtr, HWND_TOPMOST,
0,
0,
0,
0,
1 |
2);
-
SetWindowPos(intPtr, HWND_NOTOPMOST,
0,
0,
0,
0,
1 |
2);
-
SetForegroundWindow(intPtr);
-
-
}
-
-
Shutdown();
-
}
-
}
-
[
DllImport("User32", CharSet = CharSet.Unicode)]
-
static extern IntPtr FindWindowW(String lpClassName, String lpWindowName);
-
[
DllImport("User32", CharSet = CharSet.Unicode)]
-
static extern Boolean SetForegroundWindow(IntPtr hWnd);
-
[
DllImport("user32.dll", CharSet = CharSet.Auto)]
-
private static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags);
-
-
[
DllImport("user32.dll")]
-
public static extern IntPtr SetFocus(IntPtr hWnd);
コード: