examples/Qt/ISFEditor/ISFEditor_app/Spout/SpoutSDK.cpp
// SelectSenderPanel - used by a receiver
// Optional message argument

used by a receiver
Optional message argument
used by a receiver Optional message argument
bool Spout::SelectSenderPanel(const char *message)
{
	HANDLE hMutex1;
	HMODULE module;
	char UserMessage[512];
	char path[MAX_PATH], drive[MAX_PATH], dir[MAX_PATH], fname[MAX_PATH];
	if(message != NULL && message[0] != 0)
		strcpy_s(UserMessage, 512, message); 
	else
		UserMessage[0] = 0; 
	hMutex1 = OpenMutexA(MUTEX_ALL_ACCESS, 0, "SpoutPanel");
	if (!hMutex1) {
		if(!ReadPathFromRegistry(path, "Software\\Leading Edge\\SpoutPanel", "InstallPath")) {
			module = GetModuleHandle(NULL);
			GetModuleFileNameA(module, path, MAX_PATH);
			_splitpath_s(path, drive, MAX_PATH, dir, MAX_PATH, fname, MAX_PATH, NULL, 0);
			_makepath_s(path, MAX_PATH, drive, dir, "SpoutPanel", ".exe");
			if(!PathFileExistsA(path) ) {
				if(_getcwd(path, MAX_PATH)) {
					strcat_s(path, MAX_PATH, "\\SpoutPanel.exe");
					if(!PathFileExistsA(path) ) {
						return false;
					}
				}
			}
		}
		ZeroMemory(&m_ShExecInfo, sizeof(m_ShExecInfo));
		m_ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
		m_ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
		m_ShExecInfo.hwnd = NULL;
		m_ShExecInfo.lpVerb = NULL;
		m_ShExecInfo.lpFile = (LPCSTR)path;
		m_ShExecInfo.lpParameters = UserMessage;
		m_ShExecInfo.lpDirectory = NULL;
		m_ShExecInfo.nShow = SW_SHOW;
		m_ShExecInfo.hInstApp = NULL;	
		ShellExecuteExA(&m_ShExecInfo);
		Sleep(125); 
		bSpoutPanelOpened = true;
	}
	else {
		CloseHandle(hMutex1);
	}
	HWND hWnd = FindWindowA(NULL, (LPCSTR)"SpoutPanel");
	if(IsWindow(hWnd)) {
		SetForegroundWindow(hWnd); 
		SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_ASYNCWINDOWPOS | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
	}
	return true;
}
bool Spout :: SelectSenderPanel ( const char * message ) { HANDLE hMutex1 ; HMODULE module ; char UserMessage [ 512 ] ; char path [ MAX_PATH ] , drive [ MAX_PATH ] , dir [ MAX_PATH ] , fname [ MAX_PATH ] ; if ( message != NULL && message [ 0 ] != 0 ) strcpy_s ( UserMessage , 512 , message ) ; else UserMessage [ 0 ] = 0 ; hMutex1 = OpenMutexA ( MUTEX_ALL_ACCESS , 0 , " " ) ; if ( ! hMutex1 ) { if ( ! ReadPathFromRegistry ( path , " \\ \\ " , " " ) ) { module = GetModuleHandle ( NULL ) ; GetModuleFileNameA ( module , path , MAX_PATH ) ; _splitpath_s ( path , drive , MAX_PATH , dir , MAX_PATH , fname , MAX_PATH , NULL , 0 ) ; _makepath_s ( path , MAX_PATH , drive , dir , " " , " " ) ; if ( ! PathFileExistsA ( path ) ) { if ( _getcwd ( path , MAX_PATH ) ) { strcat_s ( path , MAX_PATH , " \\ " ) ; if ( ! PathFileExistsA ( path ) ) { return false ; } } } } ZeroMemory ( & m_ShExecInfo , sizeof ( m_ShExecInfo ) ) ; m_ShExecInfo . cbSize = sizeof ( SHELLEXECUTEINFO ) ; m_ShExecInfo . fMask = SEE_MASK_NOCLOSEPROCESS ; m_ShExecInfo . hwnd = NULL ; m_ShExecInfo . lpVerb = NULL ; m_ShExecInfo . lpFile = ( LPCSTR ) path ; m_ShExecInfo . lpParameters = UserMessage ; m_ShExecInfo . lpDirectory = NULL ; m_ShExecInfo . nShow = SW_SHOW ; m_ShExecInfo . hInstApp = NULL ; ShellExecuteExA ( & m_ShExecInfo ) ; Sleep ( 125 ) ; bSpoutPanelOpened = true ; } else { CloseHandle ( hMutex1 ) ; } HWND hWnd = FindWindowA ( NULL , ( LPCSTR ) " " ) ; if ( IsWindow ( hWnd ) ) { SetForegroundWindow ( hWnd ) ; SetWindowPos ( hWnd , HWND_TOPMOST , 0 , 0 , 0 , 0 , SWP_ASYNCWINDOWPOS | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE ) ; } return true ; }
SelectSenderPanel - used by a receiver
Optional message argument
SelectSenderPanel - used by a receiver Optional message argument
// could be an arg or a user message
 // make sure SpoutPanel does not see an un-initialized string
 // For a texture share receiver pop up SpoutPanel to allow the user to select a sender
 // The selected sender is then the "Active" sender and this receiver switches to it.
 // SpoutPanel.exe has to be in the same folder as this executable
 // This rather complicated process avoids having to use a dialog within a dll
 // which causes problems with FreeFrameGL plugins and Max eternals
 // First check whether the panel is already running
 // Try to open the application mutex.
 // No mutex, so not running, so can open it
 // See if there has been a Spout installation >= 2.002 with an install path for SpoutPanel.exe
 // Path not registered so find the path of the host program
 // where SpoutPanel should have been copied
 // Does SpoutPanel.exe exist in this path ?
 // Try the current working directory
 // printf("SpoutPanel cwd [%s]\n", path);
 // Does SpoutPanel exist here?
 // printf("SpoutPanel path [%s]\n", path); // Spoutpanel exists
 // 
 // Use  ShellExecuteEx so we can test its return value later
 //
 // allow time for SpoutPanel to open 0.125s
 // Returns straight away here but multiple instances of SpoutPanel
 // are prevented in it's WinMain procedure by the mutex.
 // An infinite wait here causes problems.
 // The flag "bSpoutPanelOpened" is set here to indicate that the user
 // has opened the panel to select a sender. This flag is local to 
 // this process so will not affect any other receiver instance
 // Then when the selection panel closes, sender name is tested
 // We opened it so close it, otherwise it is never released
 // The mutex exists, so another instance is already running
 // Find the dialog window and bring it to the top
 // the spout dll dialog is opened as topmost anyway but pop it to
 // the front in case anything else has stolen topmost
 // prevent other windows from hiding the dialog
 // and open the window wherever the user clicked
