Answer the question
In order to leave comments, you need to log in
Why doesn't FindWindow return the window id on first run?
There is a WPF application that receives command line arguments as input at startup, and passes them through SendMessage to the first running instance of the application, here is the code:
class Program : Application
{
[System.STAThreadAttribute()]
public static void Main() {
bool createdNew = true;
using (Mutex mtx = new Mutex(true, "AudioPlayer", out createdNew)) {
if (createdNew)
{
Program app = new Program();
app.InitializeComponent();
app.Run();
}
else {
MessageHelper msg = new MessageHelper();
int result = 0;
int hWnd = msg.getWindowId(null, "AudioPlayer");
result = msg.sendWindowsStringMessage(hWnd, 0, Environment.GetCommandLineArgs()[1]);
}
}
}
public void InitializeComponent() {
this.StartupUri = new Uri("MainWindow.xaml", System.UriKind.Relative);
}
}
Answer the question
In order to leave comments, you need to log in
I'm afraid to seem unconstructive, but: Can your "running" application have elementary checks on the result that the functions it uses return? Or maybe a debug log? If it were present, the issue would not arise.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question