مشکل رو حل کردم
برای ارسال پیام
[DllImport("user32")]
public static extern int RegisterWindowMessage(string message);
public static int RegisterWindowMessage(string format, params object[] args)
{
string message = String.Format(format, args);
return RegisterWindowMessage(message);
}
public const int HWND_BROADCAST = 0xffff;
[DllImport("user32")]
public static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);
public static readonly int WM_SHOWFIRSTINSTANCE = RegisterWindowMessage("WM_SHOWFIRSTINSTANCE|{0}", "test");
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
if (!ApplicationHelper.IsSingleInstance())
{
PostMessage((IntPtr)HWND_BROADCAST, WM_SHOWFIRSTINSTANCE, IntPtr.Zero, IntPtr.Zero);
Environment.Exit(0);
}
}
و دریافت پیام
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
HwndSource hWndSource;
WindowInteropHelper wih = new WindowInteropHelper(this);
hWndSource = HwndSource.FromHwnd(wih.Handle);
HwndSourceHook eventHandler = (IntPtr hwnd, int msg, IntPtr param, IntPtr lParam, ref bool handled) =>
{
if (msg == WM_SHOWFIRSTINSTANCE)
{
Show();
}
return IntPtr.Zero;
};
hWndSource.AddHook(eventHandler);
}
الان رو حالت تسکبار هم جواب میده