Previous Instance



I need some help on how to detect a previous instance.

My need is this:

Clicking an icon (shortcut or exe), starts the app. If you click the icon
again, the first instance recieves focus and the second instance closes.

I found some code in the API-Guide using DdeConnect which works well but has
a bug. When you click the icon a second time, although the first instance
becomes visible, I cannot get it to be the foreground window. It will be
active but have no keyboard focus. All APIs have failed trying to give it
focus. It seems the window with the icon keeps the focus. If the first
instance is minimized (i.e. at the bottom of the z-order) and you have other
windows visible, when the app becomes visible, it remains at the bottom of
the z-order. I could use SetWindowPos to get it to the top, but it still
doesn't have keyboard focus.

Any ideas?


.



Relevant Pages

  • Re: God I hate Spotlight
    ... He said there was a triangle under the icon in the dock (and ... then the window appeared (that reminds me to install the ... icon in the dock and how to open a new 'window' if the app is still ...
    (uk.comp.sys.mac)
  • Closed thread- Anyone seen this before?
    ... So it was technically on the desktop, which is why it showed up as an app ... I make it go away by closing the window - I get a little window that just ... 'Address' a text entry box and a little IE style 'Go' icon. ... Killing it in Task Manager kills explorer, which at least on my machine then ...
    (Incidents)
  • Re: How to find windows which r minimized to the system tray
    ... For one thing a window is not minimized to the system tray, ... Then, when the user clicks on the icon, ... app when it set up the icon in the first place. ...
    (microsoft.public.vb.winapi)
  • Re: Newbe questions
    ... > remember almost by heart icon at which location represents what. ... > But now I'm new to the RedHat LINIX on KDE and the default behaviour ... > Is there a way to start an app with geometry args ... You will also find here a text editor called "textedit" which I ...
    (comp.os.linux.misc)
  • Re: Tray Icons and custom shell
    ... messages to SysTray to forwarding WM_COMMAND event to some other parts or windows of the same app). ... PostMessage to send the appropriate command to the tray icon window. ... I've a custom shell and therefore no system tray. ...
    (microsoft.public.windowsxp.embedded)