Board index » delphi » ShellExecute problem

ShellExecute problem

Hi guys,

I have a program that launches other programs and currentl;y I am
using WinExec to launch them.

If I use ShellExecute I get "an undeclared identifier" error. My guess
is that I need to add a unit to the "uses" clause but can find no
indication as to which unit. The Help system does not outline it.

OK, the next problem.

After the "launched" program has terminated I need to see if it has
modified any of it's configuratoion files on closing. If it has, then
I need to copy them to a backup directory.

The problem is that once the program has been "launched" my program
has no way of knowing when the "launched" program has been closed, and
therefore no way of knowing if the files need checking to see if they
have to be backed up.

Finally a third and annoying problem that I can live with but would be
nice to fix.

I have a listbox with the various program names to launch. When I
single-click on one, I have an OnClick event that needs checking. I
would also like to use the OnDoubleClick event to launch the program
but it first handles the OnClick event, then the OnDoubleClick.

The problem here is that the OnClick event sometimes has a MessageDlg
that pops up depending on certain conditions. If that's the case then
the second click is ignored because the dialog is open by that time.

I had assumed that a double click would be handled as a distinct and
seperate event rather than processing the first of the two clicks
individually, and then discovering it was a bouble click. The
OnDoubleCkick works fine if the OnClick event doesn't have to open the
MessageDlg.

I have tried everything I can think off, so any help here will be
greatly appreciated.

Peter

 

Re:ShellExecute problem


Quote
>If I use ShellExecute I get "an undeclared identifier" error. My guess
>is that I need to add a unit to the "uses" clause but can find no
>indication as to which unit. The Help system does not outline it.

Try adding the ShellApi unit

Quote
>After the "launched" program has terminated I need to see if it has
>modified any of it's configuratoion files on closing. If it has, then
>I need to copy them to a backup directory.

Ok - make a CRC of the conf. files

Quote
>The problem is that once the program has been "launched" my program
>has no way of knowing when the "launched" program has been closed, and
>therefore no way of knowing if the files need checking to see if they
>have to be backed up.

The ShellExecute returns the instance of the program launched. Check if the
instance still is "alive"

Quote
>I have a listbox with the various program names to launch. When I
>single-click on one, I have an OnClick event that needs checking. I
>would also like to use the OnDoubleClick event to launch the program
>but it first handles the OnClick event, then the OnDoubleClick.

Hmmm - donno. Maybe you're not clicking fast enough ;-)

Janus N. T?ndering

Re:ShellExecute problem


Peter,

I see you've gotten several answers to your question about
ShellExecute... so I'll skip that one.

The answer to your second question, though, is to use CreateProcess
instead, and WaitForSingleObject to wait until the 'launched'
program is done. For a quick and easy example of how to do this,
go to http://developers.href.com/search, and use 'WinExecAndWait32
and Peter and Below' as the search string. You'll find a full
function that does just what you're looking for...

Ken
--
Ken White
kwh...@westelcom.com

Clipper Functions for Delphi
http://members.aol.com/clipfunc/

Quote
Peter Nolan wrote:

> Hi guys,

> I have a program that launches other programs and currentl;y I am
> using WinExec to launch them.

> If I use ShellExecute I get "an undeclared identifier" error. My guess
> is that I need to add a unit to the "uses" clause but can find no
> indication as to which unit. The Help system does not outline it.

> OK, the next problem.

> After the "launched" program has terminated I need to see if it has
> modified any of it's configuratoion files on closing. If it has, then
> I need to copy them to a backup directory.

> The problem is that once the program has been "launched" my program
> has no way of knowing when the "launched" program has been closed, and
> therefore no way of knowing if the files need checking to see if they
> have to be backed up.

> Finally a third and annoying problem that I can live with but would be
> nice to fix.

> I have a listbox with the various program names to launch. When I
> single-click on one, I have an OnClick event that needs checking. I
> would also like to use the OnDoubleClick event to launch the program
> but it first handles the OnClick event, then the OnDoubleClick.

> The problem here is that the OnClick event sometimes has a MessageDlg
> that pops up depending on certain conditions. If that's the case then
> the second click is ignored because the dialog is open by that time.

> I had assumed that a double click would be handled as a distinct and
> seperate event rather than processing the first of the two clicks
> individually, and then discovering it was a bouble click. The
> OnDoubleCkick works fine if the OnClick event doesn't have to open the
> MessageDlg.

> I have tried everything I can think off, so any help here will be
> greatly appreciated.

> Peter

Re:ShellExecute problem


Janus N. T?ndering nusperson wrote:

Quote
> The ShellExecute returns the instance of the program launched. Check if the
> instance still is "alive"

And how can I do that in BPW?
I can't find anything about it.

Andras

Re:ShellExecute problem


Quote
On Tue, 04 Aug 1998 16:06:33 +0200, Papai Andras <APa...@mol.hu> wrote:
> Janus N. T0ndering nusperson wrote:

> > The ShellExecute returns the instance of the program launched. Check if the
> > instance still is "alive"

> And how can I do that in BPW?

You are about to go where no 'newbie' has ever been before. :-)

Quote
> I can't find anything about it.

A quick pointer on getting help in BPW 7.0

You start editing a program and type the word ShellExecute and press
Crtl-F1 while the cursor is on the word.

Or for an ALL word search you click

   Help / Topic Search / Find

and enter the word your looking for....or in the case that your not sure
of the word -- say Shell?????? -- start typing the word and you get
context sensitive help.  Just the word Shell gets you 37 topics to look
at.  

Now you should be a Wiz at finding words in the on-line help.  But
interpreting the results is something else.....

Quote

> Andras

Steve
Use my address below for replies
Email: smr...@linkny.com
SPAM and JUNKMAIL not appreciated.

Re:ShellExecute problem


On 03 Aug 1998 22:01:00 GMT, cehjohn...@aol.com (CEHJohnson) wrote:

Quote
>>1. ShellExecute is in the ShellAPI unit - add it to your uses.

Thanks, I tried the Help system to no avail, but that sure fixed it.

Quote
>>2. What I would do here is poll for the other app's main window in a separate
>>thread. Use FindWindow and when it returns zero, start your checking.

Ok, I'll go search the Help files again. A code snippet of FindWindow
would be appreciated.

Quote
>>3. I would really try and implement this functionality in a different way-
>>single and double clicks are too close to each other, and user error-prone - eg
>>it would be very easy to give the user the headache of launching an app
>>accidentally - make them work a bit more

Thanks Charkes you are right, I will do away with the OnClick and just
use the OnDouble to launch.

Regards

Peter Nolan
CEO - Nolan Innovation Inc.
*******************************
http://aluminator.tierranet.com
Ph 520-772-9730
Cellular 520-713-7016
Fax 520-772-9839
***********************************

Re:ShellExecute problem


Peter,

On second thoughts, since your polling operation doesn't need to be too system
resource-hungry, it's probably adequate to implement polling in a timer.

1. Drop a timer onto your form.
2. Set Enabled to false and Interval to your polling requirement.
3. Add the following and load and unload Notepad:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if FindWindow('Notepad',nil) <> 0 then
  Caption := 'Notepad loaded'
  else Caption := 'Notepad not loaded'
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Timer1.Enabled := true;
end;

Good luck

Charles Johnson

Re:ShellExecute problem


On Mon, 03 Aug 1998 23:44:55 -0400, in comp.lang.pascal.delphi.misc

Quote
you wrote:
>>The answer to your second question, though, is to use CreateProcess
>>instead, and WaitForSingleObject to wait until the 'launched'
>>program is done. For a quick and easy example of how to do this,
>>go to http://developers.href.com/search, and use 'WinExecAndWait32
>>and Peter and Below' as the search string. You'll find a full
>>function that does just what you're looking for...

Wow, Ken,

Thanks very much. That will do it I am sure. I have a Delphi
Developers guide by Pacheco and Teixera that had a WinExecAndWait but
it used GetModuleUsage and that, as winHelp said, has been deleted.

I really appreciate the pointer the 32version.

Thanks again.

Peter

Regards

Peter Nolan
CEO - Nolan Innovation Inc.
*******************************
http://aluminator.tierranet.com
Ph 520-772-9730
Cellular 520-713-7016
Fax 520-772-9839
***********************************

Other Threads