Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

destroying a window

Posted on 1999-07-09
7
Medium Priority
?
245 Views
Last Modified: 2010-04-02
Hi,
In my application when a menu item is click on, Notepad is used to open up a text file. What i want to happen i as follows.  I don't what the rest of the function to execute until after Notepad is closed.  Is there anyway that i can tell from within my function whether the Notepad window has been closed/destroyed so that function can continue executing?
0
Comment
Question by:shikari
[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
7 Comments
 

Accepted Solution

by:
corodent earned 400 total points
ID: 1199644
Use CreateProcess to start Notepad.  CreateProcess will return a process handle.  Do a WaitForSingleObject (or moral equivalent) on the process handle and it will be signalled when the process exits.
0
 

Author Comment

by:shikari
ID: 1199645
thanks. i'm having a little trouble getting the CreateProcess function to work.
THis is how i'm calling it.
if( !CreateProcess(0, "Notepad c:\\windows\\desktop\\faxback.txt",
NULL, NULL, 1, NORMAL_PRIORITY_CLASS, NULL, NULL, NULL, &process))
              AfxMessageBox("failure");

do you see anything wrong with this?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1199646
yes, the function should look like this...

f( !CreateProcess(0, "Notepad c:\\windows\\desktop\\faxback.txt",
     NULL, NULL, 1, NORMAL_PRIORITY_CLASS, NULL, NULL, &startupinfo,
     &process))

so you need to create that stracture also...

..-=ViKtOr=-..
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 22

Expert Comment

by:nietod
ID: 1199647
Also, be sure to close the thread handle and process handle to the new process (returned to you inside the "process" structure) when you are done with them.
0
 

Expert Comment

by:Oliv
ID: 1199648
could be usefull : CWnd::FindWindow(...) ...
0
 

Expert Comment

by:corodent
ID: 1199649
I am finally at a computer with a compiler so here is the source code for a command line app which launches Notepad and waits for it to close:

#include <windows.h>
#include <stdio.h>

void main( int argc, char **argv ) {
      STARTUPINFO si ;
      PROCESS_INFORMATION pi ;

      memset( &si, 0, sizeof(si) ) ;
      si.cb = sizeof(si) ;
      si.wShowWindow = SW_SHOW ;
      
      if( !CreateProcess( NULL, "notepad.exe c:\\temp\\t", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ) ) {
            printf( "ERROR: CreateProcess failed\n" ) ;
            return ;
      }

      CloseHandle( pi.hThread ) ;
      WaitForSingleObject( pi.hProcess, INFINITE ) ;
      CloseHandle( pi.hProcess ) ;
      
      printf( "Notepad closed\n" ) ;
}

0
 

Author Comment

by:shikari
ID: 1199650
Thank you very much!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

664 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