0

I have a singleton application that can be minimized to the system tray. It can happen that the user starts another instance of the application, and with _singleton I detect the first instance of the script and I activate the window before exiting the new instance.

However when the first instance is hidden with GUISetState(@SW_HIDE) the first instance is not showing up. I tried to get the window handle, but no success.

How can I unhide the first instance?

Consider the below code snippet:

If _Singleton("MyApp.exe", 1) = 0 Then
    GUISetState(@SW_SHOW, WinGetHandle("MyApp.exe"))
    WinActivate("MyApp")
    Exit
EndIf
ib11
  • 2,530
  • 3
  • 22
  • 55

1 Answers1

0

WinGetHandle() does not take an exe name as a parameter. It takes a window title. You could give your hidden window a unique name that isn't likely to be used by another application and use that to get the handle.

Or you could try using _WinAPI_RegisterWindowMessage() in a simplified version of the code here or here to send a message from one instance of your application to the other instance which could unhide the window.

garbb
  • 679
  • 5
  • 9