Solved

Spawning another application from MFC application

Posted on 1998-10-29
2
205 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 190
iSeries FTP Exit Program 8 147
string initialization in java 11 115
Line meaning 9 88
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.

830 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