Solved

Spawning another application from MFC application

Posted on 1998-10-29
2
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

696 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