Re: How can I find out if a program is already running



Zoltan Boszormenyi wrote:
Hi,

I need to find out whether an instance of a program is already running
and possibly unminimize it or bring it above any other windows, so
I can prevent an application started again.
Is is possible using GTK-1.2, or GTK-2.x, and how?


The following procedure is an old X11 trick. It will not work on Windows.

0. Add code to your program to handle GDK_SELECTION_CLEAR events. See 5 below for what this code should do.

1. At startup of the program, create an atom with gdk_intern_atom().

2. Use gdk_selection_owner_get() on the atom.

3. If the selection owner is NULL, then call gdk_selection_owner_set() with the time_ parameter set to GDK_CURRENT_TIME and the send_event parameter set to FALSE.

4. Else, there is a valid owner of the atom, so the program is already running. Assert ownership of the selection with gdk_selection_owner_set() again. This causes the running application to lose ownership and call the code to handle GDK_SELECTION_CLEAR events. Then exit.

5. The code to handle GDK_SELECTION_CLEAR events should do 2 things:
  A. If minimized, unminimize.
  B. Assert ownership of the selection again.

This doesn't work on Windows because the GDK selection API apparently only works within applications and not globally like they do in X11.
--
---------------------------------------------------------------------------
Mark Leisher
Computing Research Lab            A sneer is the weapon of the weak.
New Mexico State University         -- James Russell Lowell (1819-1891)
Box 30001, MSC 3CRL
Las Cruces, NM  88003



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]