We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now



djamal asked
Medium Priority
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???

Watch Question

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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

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.

It is advisable to use CreateProcess() instead of WinExec() for Win32.


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...


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.


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.?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.