Solved

winexec

Posted on 1997-05-01
6
629 Views
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:

WinExec("notepad.exe");
...????

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

Thanks,
                                          Dja.
 
 
0
Comment
Question by:djamal
  • 2
  • 2
  • 2
6 Comments
 

Accepted Solution

by:
footloose earned 20 total points
Comment Utility
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.

0
 
LVL 4

Expert Comment

by:mbhakta
Comment Utility
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.
0
 
LVL 4

Expert Comment

by:mbhakta
Comment Utility
It is advisable to use CreateProcess() instead of WinExec() for Win32.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:djamal
Comment Utility
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...

Thanks,


                                    Dja.
0
 

Expert Comment

by:footloose
Comment Utility
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.
0
 

Author Comment

by:djamal
Comment Utility
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.?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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 video discusses moving either the default database or any database to a new volume.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now