Exemplo n.º 1
0
void CDirstatApp::RestartApplication()
{
	// First, try to create the suspended process
	STARTUPINFO si;
	ZeroMemory(&si, sizeof(si));
	si.cb= sizeof(si);

	PROCESS_INFORMATION pi;
	ZeroMemory(&pi, sizeof(pi));

	BOOL success = CreateProcess(GetAppFileName(), NULL, NULL, NULL, false, CREATE_SUSPENDED, NULL, NULL, &si, &pi);
	if (!success)
	{
		CString s;
		s.FormatMessage(IDS_CREATEPROCESSsFAILEDs, GetAppFileName(), MdGetWinerrorText(GetLastError()));
		AfxMessageBox(s);
		return;
	}

	// We _send_ the WM_CLOSE here to ensure that all CPersistence-Settings
	// like column widths an so on are saved before the new instance is resumed.
	// This will post a WM_QUIT message.
	GetMainFrame()->SendMessage(WM_CLOSE);

	DWORD dw= ::ResumeThread(pi.hThread);
	if (dw != 1)
		TRACE(_T("ResumeThread() didn't return 1\r\n"));

	CloseHandle(pi.hProcess);
	CloseHandle(pi.hThread);
}
Exemplo n.º 2
0
void CDirstatApp::RestartApplication( ) {
	// First, try to create the suspended process
	
	auto si = zeroInitSTARTUPINFO( );
	si.cb = sizeof( si );

	auto pi = zeroInitPROCESS_INFORMATION( );
	
	auto appFileName = GetAppFileName( );

	BOOL success = CreateProcess( appFileName, NULL, NULL, NULL, false, CREATE_SUSPENDED, NULL, NULL, &si, &pi );
	if (!success) {
		CString c = _T( "CreateProcess( " );
		c += appFileName;
		c += _T( ") failed: " );
		c += GetLastErrorAsFormattedMessage( );
		AfxMessageBox( c );
		CloseHandle( pi.hProcess );
		CloseHandle( pi.hThread );
		return;
		}

	// We _send_ the WM_CLOSE here to ensure that all CPersistence-Settings like column widths an so on are saved before the new instance is resumed.
	// This will post a WM_QUIT message.
	GetMainFrame( )->SendMessage( WM_CLOSE );

	DWORD dw = ::ResumeThread( pi.hThread );
	if ( dw != 1 ) {
		TRACE( _T( "ResumeThread() didn't return 1\r\n" ) );
		}
	CloseHandle( pi.hProcess );
	CloseHandle( pi.hThread );
	}
Exemplo n.º 3
0
int CConnectionSettingsAdvanced::DoModal(CConnectionSettings *pConnSettings)
   {
      int      nRetVal;

      ASSERT(pConnSettings);
      if(pConnSettings == NULL)
         return IDCANCEL;

      m_pConnSettings = pConnSettings;
      SetAppTitle(m_pConnSettings->GetName());
      SetAppFileName(m_pConnSettings->GetAppFileName());
      SetTimeOut(m_pConnSettings->GetTimeOut());
      SetFirstCheck(m_pConnSettings->GetFirstCheck());
      m_bUsesDialup = m_pConnSettings->WatchForDialup();
      m_bRestoreAutodial = m_pConnSettings->RestoreAutodial();

      nRetVal = CDialog::DoModal();

      if(nRetVal == IDOK)
         {
            m_pConnSettings->SetTimeOut(GetTimeOut());
            m_pConnSettings->SetFirstCheck(GetFirstCheck());
            m_pConnSettings->SetName(GetAppTitle());
            m_pConnSettings->SetAppFileName(GetAppFileName());
            m_pConnSettings->SetWatchForDialup(m_bUsesDialup);
            m_pConnSettings->SetRestoreAutodial(m_bRestoreAutodial);
            m_pConnSettings->SaveSettings();
         }
      return nRetVal;
   }
Exemplo n.º 4
0
CString GetAppFolder()
{
	CString s= GetAppFileName();
	int i= s.ReverseFind(_T('\\'));
	ASSERT(i >= 0);
	s= s.Left(i);
	return s;
}
Exemplo n.º 5
0
bool FileMisc::LogText(LPCTSTR szLine, bool bWantDateTime)
{
	CString sLogFile = GetAppFileName();
	ReplaceExtension(sLogFile, _T(".log"));

	CString sLogLine(szLine);

	if (bWantDateTime)
	{
		sLogLine += _T(" (");
		sLogLine += COleDateTime::GetCurrentTime().Format();
		sLogLine += _T(")");
	}

	return AppendLineToFile(sLogFile, sLogLine);
}
Exemplo n.º 6
0
bool iLog::EnsureOpen()
{
	if ( !m_File && !m_Failed ) 
	{
		m_File = new iFile();
		if (!m_File) 
		{
			m_Failed = true;
			return false;
		}

		iStringT fname(GetAppPath() + GetAppFileName() + _T(".iolog"));
		if (!m_File->Create( fname ))
		{
			delete m_File;
			m_File = NULL;
			m_Failed = true;
			return false;
		}
		if ( m_File ) atexit( iLog::Close );
	}
	if ( m_File ) return true;
	return false;
}
Exemplo n.º 7
0
static DWORD OsThreadFunction (DWORD param)
{
	WNDCLASSEX wclass;
	int width, height;
	HMENU mainSystemMenu;

	/* register main window class */
	wclass.cbSize        = sizeof (WNDCLASSEX);
	wclass.style         = CS_NOCLOSE;
	wclass.lpfnWndProc   = (WNDPROC) MainWindowProcedure;
	wclass.cbClsExtra    = 0;
	wclass.cbWndExtra    = 0;
	wclass.hInstance     = ghInst;
	wclass.hIcon         = LoadIcon (ghInst, IDI_APPLICATION);
	wclass.hCursor       = LoadCursor (ghInst, IDC_ARROW);
	wclass.hbrBackground = NULL;
	wclass.lpszMenuName  = NULL;
	wclass.lpszClassName = MainWindowClassName;
	wclass.hIconSm       = NULL;
	RegisterClassEx (&wclass);

	GetAppFileName ();

	width  =     GetSystemMetrics (SM_CXMAXIMIZED) - 2 * GetSystemMetrics (SM_CXSIZEFRAME);
	height = 2 * GetSystemMetrics (SM_CYSIZEFRAME) + GetSystemMetrics (SM_CYCAPTION) + GetSystemMetrics (SM_CYMENU);

	ghMainWindow
		= CreateWindow (MainWindowClassName,	/* Class name					 */
						(LPCTSTR) gAppName, 	/* Window title 				 */
						WS_OVERLAPPEDWINDOW,	/* style flags					 */
						0, -5 - height,			/* x, y 						 */
						width, height,			/* width, height 				 */
						NULL,					/* Parent window				 */
						NULL,					/* menu handle					 */
						(HANDLE) ghInst,		/* Instance that owns the window */
						0);
	/*	Don't show the main window. This will result in one button less in the taskbar.
	ShowWindow (ghMainWindow, SW_SHOWNORMAL);
	*/
	/*	Before creating Clean controls, the tooltip control is created as the topmost child of this window. */
	gTooltip = CreateWindowEx (	WS_EX_TOPMOST,					// Apply the topmost style for this window
								TOOLTIPS_CLASS,					// Class name
								NULL,							// Title (NULL)
								WS_POPUP | TTS_ALWAYSTIP,		// Style *must* be WS_POPUP
								CW_USEDEFAULT,					// Default position (x,y)
								CW_USEDEFAULT,
								CW_USEDEFAULT,					// Default size (w,h)
								CW_USEDEFAULT,
								ghMainWindow,					// Parent is the ghMainWindow
								(HMENU) NULL,					// No menu
								(HANDLE) ghInst,				// The instance
								NULL							// No window creation data
							 );

	mainSystemMenu = GetSystemMenu (ghMainWindow,FALSE);
	RemoveMenu (mainSystemMenu, SC_RESTORE,  MF_BYCOMMAND);
	RemoveMenu (mainSystemMenu, SC_MOVE,     MF_BYCOMMAND);
	RemoveMenu (mainSystemMenu, SC_SIZE,     MF_BYCOMMAND);
	RemoveMenu (mainSystemMenu, SC_MINIMIZE, MF_BYCOMMAND);
	RemoveMenu (mainSystemMenu, SC_MAXIMIZE, MF_BYCOMMAND);
	DrawMenuBar (ghMainWindow);

	KickCleanThread (MakeReturn0Cci (&gCci));

	while (1)
	{
		HandleCleanRequest (&gCci);
	}

	MakeReturn0Cci (&gCci);
	SetEvent (gOS_DONE);

	return 0;
}	/* OsThreadFunction */