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 » U++ Library support » TopWindow&PopUp, TrayIcon » How to check whether application is running
Re: How to check whether application is running [message #27875 is a reply to message #27874] Mon, 09 August 2010 04:16 Go to previous messageGo to previous message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
I´ve been proceeding as follows:
// global function:
HWND GetRunningWindow() {
	// Check if exists an application with the same TITLE as this application
	HWND hWnd = FindWindow(NULL, "My TopWindow Title");
	if (IsWindow(hWnd))	{
		HWND hWndPopup = GetLastActivePopup(hWnd);
		if (IsWindow(hWndPopup))
		hWnd = hWndPopup; // Previous instance exists
	} else {
		hWnd = NULL; // Previous instance doesnt exist
	}
	return hWnd;
}

GUI_APP_MAIN
{
	// Checks for previous instance of our app
	HWND hOtherWnd = GetRunningWindow();
	// Allow only one app instance
	if (hOtherWnd) {// hOtherWnd != NULL -> Previous instance exists
		PromptOK("The program is already running");
		SetForegroundWindow(hOtherWnd); // Activate it &
		if (IsIconic(hOtherWnd))
			ShowWindow(hOtherWnd, SW_RESTORE); // restore it
		return; // Abort current app execution
	}
	
// ... otherwise, run app here ...

}


Thanks again.

[Updated on: Mon, 09 August 2010 04:29]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: TopWindow minimum size
Next Topic: Timeout on PromptYesNo?
Goto Forum:
  


Current Time: Thu May 09 03:53:31 CEST 2024

Total time taken to generate the page: 0.02806 seconds