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 » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » Just one instance of application running (SingleApp)
Re: Just one instance of application running (SingleApp) [message #24638 is a reply to message #24634] Tue, 26 January 2010 09:37 Go to previous messageGo to previous message
koldo is currently offline  koldo
Messages: 3437
Registered: August 2008
Senior Veteran
Hello Sc0rch

I have compiled your original version and final version and none of them work for me Sad

I have changed them a little and now they work for me:

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):
#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
Koldo


Best regards
IƱaki
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Port giFT (a great but abandoned P2P project) to U++?
Next Topic: array vs. array's items.id sorting/searching
Goto Forum:
  


Current Time: Fri Jul 18 05:45:55 CEST 2025

Total time taken to generate the page: 0.04431 seconds