Posted on 1997-05-01
Last Modified: 2013-11-20
Environment: VC++1.52, Win3.11

Hi All,

I have a little question.

In my program i open a notepad.exe by using WinExec:


What i can put just after WinExec, in order my program wait until the user close
the notepad program???

Question by:djamal
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
  • 2

Accepted Solution

footloose earned 20 total points
ID: 1301255
After successful WinExec, use FindWindow to get the title of the NotePad window. The title will be unique, because it will be something like "filename - NotePad".

Start a timer that periodically checks for the existence of a window with that title. Then set focus to NotePad. If the timer callback finds that the window does not exist anymore, then it gets focus and does the necessary stuff.

If you want stricter control, you might want to try subclassing the app.


Expert Comment

ID: 1301256
Sorry to interrupt your discussion. But just a point to make. The FindWindow() would not work for titles texts, if you plan to use it for international windows versions as Notepad has different names under different languages and hence findwindow w.r.t title will not successed. I recommend using Findwindow w.r.t the class name i.e. "Notepad".

I agree with the timer to some extent, Once the notepad is found , you can use the CDialog::DoModal() technique where the parent window is disabled and notepad is on top. This way you can give Notepad a modal dialog feel. Get your timer to enable your window and bring it on top once it finds the Notepad window has been destroyed.

Expert Comment

ID: 1301257
It is advisable to use CreateProcess() instead of WinExec() for Win32.
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.


Author Comment

ID: 1301258
Hi All,

About the arguments of FindWindow:

How i can know the class name and window name of my application?

And in general how i can know the class name and window name of window
application like notepad, word, control panel etc...



Expert Comment

ID: 1301259
I agree with mbhakta on using the classname rather than the title. Class name for notepad is "Notepad". Give a NULL pointer argument for the title.
Use SPY.EXE to find the class name of apps.
The class name of your app is set when you create your main window. If you want to change that, register a new class and override PreCreateWindow of the mainframe to set the classname to that of yours.

Author Comment

ID: 1301260
In MainFrame, I've tried to assign class name inside virtual "PreCreateWindow", and it looked OK. However, it causes
error in "OpenDocumentFile" (msg: Fail to create empty document), then program quits.

How to change the default class name by another class name without change others parameter inside of WNDCLAS struct.?

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

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: 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…
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

624 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