Solved

Spawning another application from MFC application

Posted on 1998-10-29
2
189 Views
Last Modified: 2013-11-20
I have a VC++ application using MFC. How do I start notepad from this application and load a particular txt file in the notepad? I want to use this to display a log file generated by my application.
Thanks
0
Comment
Question by:sm176811
  • 2
2 Comments
 
LVL 7

Accepted Solution

by:
psdavis earned 50 total points
ID: 1323980
This is what I use for running one of my programs...

      HMODULE hKernel = GetModuleHandle( "KERNEL32.DLL" );

      if( hKernel != NULL )
      {
      // Find the addresses of the requested functions

         CREATESNAPSHOT hCreateToolhelp32Snapshot = (CREATESNAPSHOT) GetProcAddress( hKernel, "CreateToolhelp32Snapshot" );
         PROCESSWALK    hProcess32First           = (PROCESSWALK)    GetProcAddress( hKernel, "Process32First"           );
         PROCESSWALK    hProcess32Next            = (PROCESSWALK)    GetProcAddress( hKernel, "Process32Next"            );

         if( hCreateToolhelp32Snapshot != NULL && hProcess32First != NULL && hProcess32Next != NULL )
         {
            PROCESSENTRY32 hProcEntry;
            hProcEntry.dwSize = sizeof( hProcEntry );

            HANDLE hSnapshot = hCreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

            hProcess32First( hSnapshot, &hProcEntry );

            CString strEngine     = _T( "ENGINE.EXE" );

         // Now loop through all of the executing programs to see if the engine is already started

            bool bEngineFound = false;

            while( hProcess32Next( hSnapshot, &hProcEntry ) == TRUE )
            {
               CString strExecutable = hProcEntry.szExeFile;

               if( strExecutable.Find( strEngine ) != -1 )
               {
                  bEngineFound = true;
                  break;
               }
            }

         // OK, let's run it!

            if( bEngineFound == false )
            {
               CString strDrive, strDirectory, strFilename, strExtension;

               _splitpath(AfxGetApp()->m_pszHelpFilePath,
                          strDrive   .GetBuffer( _MAX_DRIVE ), strDirectory.GetBuffer( _MAX_DIR ),
                          strFilename.GetBuffer( _MAX_FNAME ), strExtension.GetBuffer( _MAX_EXT ) );

               ShellExecute( this->GetSafeHwnd( ), "open", strEngine, NULL, strDirectory, SW_SHOWMINIMIZED );
            }
         }
      }

Phillip
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1323981
To have notepad open up the correct file, add a parameter to notepad.exe with the name of the file that you want.

Phillip
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now