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 #24609 is a reply to message #24603] Mon, 25 January 2010 16:11 Go to previous messageGo to previous message
koldo is currently offline  koldo
Messages: 3437
Registered: August 2008
Senior Veteran
Sc0rch wrote on Mon, 25 January 2010 14:42

Header:
#ifndef SINGLE_APP_H
#define SINGLE_APP_H

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

class UniqueWindow : public TopWindow
{
public:
	typedef UniqueWindow CLASSNAME;
	UniqueWindow(){}
};

inline bool CreateSingleApp(String name, String unique, bool message = true)
{
#ifdef PLATFORM_WIN32
	name << unique;
	if(::FindWindow(NULL, name))
	{
		if (message)
			Exclamation("Another instance of application already exists!");
		return false;
	}
	Single<UniqueWindow>().SetRect(-1, -1, 1, 1);
	Single<UniqueWindow>().Hide();
	Single<UniqueWindow>().Title(name);
	Single<UniqueWindow>().Open();
#endif
	return true;
}

#endif // SINGLE_APP_H


Using:
GUI_APP_MAIN
{
	if (!CreateSingleApp("SingleApp Test", "##SingleApp##1.0"))
		return;

	MainWindow().Run();
}



Hello ScOrch

If you use GetWindowIdFromCaption() (SysInfo package) instead of FindWindow, this code will serve you for Linux too.

Sorry for the propaganda Smile

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 10:01:09 CEST 2025

Total time taken to generate the page: 0.00590 seconds