Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » Open file in already opened app instead of launching a second copy
Re: Open file in already opened app instead of launching a second copy [message #25971 is a reply to message #25970] Mon, 22 March 2010 19:36 Go to previous messageGo to previous message
koldo is currently offline  koldo
Messages: 3437
Registered: August 2008
Senior Veteran
mdelfede wrote on Mon, 22 March 2010 17:39

I wonder how that can be done...
I have a multi-document application; when it's already running I'd like, if double clicking on another document, to have the app loading the second document instead of launching a new app instance.
On Linux I did (some time ago) with my Bazaar Signals package, to tell opened app instance to load the new file before exiting.
On Windows I've no hints about....

Ciao

Max



Hello Massimo

From this post.

First version (Windows only):

#include <CtrlLib/CtrlLib.h>
using namespace Upp;

class UniqueWindow : public TopWindow
{
public:
	typedef UniqueWindow CLASSNAME;
	UniqueWindow() {
		Title("SingleApp Test");
	}
	bool IsSingleApp() {
		if(::FindWindow(NULL, GetTitle().ToString())) 
			return false;
		return true;
	}
};

GUI_APP_MAIN
{
	if (!UniqueWindow().IsSingleApp()) {
		Exclamation("Another instance of application already exists!");
		return;
	}	
	UniqueWindow().Run();
}



Second version (Windows and Linux). It requires SysInfo:

#include <CtrlLib/CtrlLib.h>
#include <SysInfo/SysInfo.h>
using namespace Upp;

class UniqueWindow : public TopWindow
{
public:
	typedef UniqueWindow CLASSNAME;
	UniqueWindow() {
		Title("SingleApp Test");
	}
	bool IsSingleApp() {
		if(GetWindowIdFromCaption(GetTitle().ToString()) > 0) 
			return false;
		return true;
	}
};

GUI_APP_MAIN
{
	if (!UniqueWindow().IsSingleApp()) {
		Exclamation("Another instance of application already exists!");
		return;
	}	
	UniqueWindow().Run();
}


Only change is to add #include <SysInfo/SysInfo.h> and instedad of FindWindow() I have used GetWindowIdFromCaption().


Best regards
IƱaki
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: libpng1.4
Next Topic: [SOLVED] Xmlize LineEdit with line breaks inside
Goto Forum:
  


Current Time: Fri Jul 18 03:42:32 CEST 2025

Total time taken to generate the page: 0.04070 seconds