avoid multiple instance of the same application

  • Thread starter Alessandro Crugnola *sephiroth*
  • Start date
A

Alessandro Crugnola *sephiroth*

Hi, i've created a wxpython app, a text editor, and then I've created the .exe file and make in myOS the file associtation to this
application.
The problem is that when an instance of the application is already opened and i double click on a file, my system open another
instance of the same file.

So, the question.. how to avoid this and open the clicked file in the previos opened application?

I've founded this piece of code on the net, this just to prevent multiple instance to be opened, but now the problem is how to tell
to the first app "open" that file..


if wxPlatform == '__WXMSW__':
# [ 838561 ] open file opens a new SEPY instance
import win32event, win32api, win32gui, win32con

myMutex = win32event.CreateMutex(None,-1,'sepy_mutex')
if win32event.WaitForSingleObject(myMutex, 0) == 0:
app = App(0)
app.MainLoop()
else:
exeName = win32api.GetModuleFileName(0)
sepyWindow = win32gui.FindWindow(0,exeName)
if not(win32gui.IsWindowVisible(sepyWindow)):
win32gui.PostMessage(sepyWindow, win32con.WM_USER, 0, 0)
win32gui.SetForegroundWindow(sepyWindow)
if len(sys.argv) > 1:
# here call opennewfile... ??
sys.exit()
else:
app = App(0)
app.MainLoop()

--

Alessandro Crugnola [sephiroth]
Flash | PHP Developer
http://www.sephiroth.it

Team Macromedia Volunteer for Flash
http://www.macromedia.com/go/team

Flash-php mailing list
http://www.flash-php.it/index.php?ml=fpcoders&action=subscribe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top