Winexec and the program can do more


when i push my button1.click and executes the code
'winexec('c:\acrobat4.exe',sw_shownormal);
and when the program is running i want my program breath i will be able to minimize my program or anything edit memo or something
traustiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MadshiCommented:
Could you explain it again please? I didn't quite understand what you mean...

Regards, Madshi.
0
brunoheCommented:
I think he wants to call Winexec first and then minimize his application. Earm... Madshi... you're damnd fast with you replys! <g>
0
traustiAuthor Commented:
i want to execute application and the application is so slow to unpack the files, so i want to be able to work in my program

e.g: minimize push a button or ??????
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

brunoheCommented:
Oh... I forgot. Did you tried

Winexec(bla...);
form.WindowState := wsminimized;

?
0
brunoheCommented:
Oh, sorry. Dont use Winexec, use ShellExecute instead. You can specify a parameter in the call (Win32 API) what should happen with your app.
0
traustiAuthor Commented:
!!!

if i use your code

//Winexec(bla...);
//form.WindowState := wsminimized;

the application will have to finish and when it is finish then the form will minimize, i want application.processmessage or something example
0
traustiAuthor Commented:
!!!

if i use your code

//Winexec(bla...);
//form.WindowState := wsminimized;

the application will have to finish and when it is finish then the form will minimize, i want application.processmessage or something example
0
traustiAuthor Commented:
have you example with ShellExecute
0
MadshiCommented:
Hi bruno-he...   :-)

Well, it was chance that I was so fast this time.

ShellExecute('calc.exe', nil, nil, nil, nil, SW_MINIMIZE);

Regards, Madshi.
0
intheCommented:
shellexecute
('handle,'open',pchar('c:\acrobat4.exe'),nil,nil,sw_minimize);
application.processmessages;
0
kifahCommented:
Hi,
If the application you need to run is to large, and need time to run, in this case you should run it within a thread.
0
kalinkCommented:
Use CreateProcess(...)
see documentation i MS SDK help

I have somewhere complete example including code to wait for the executing program to finish.
So if anybody is interested I can
try to find it.

0
MadshiCommented:
And another new expert! Welcome, kalink...   :-)

May I friendly request something? Here in the Delphi forum it is common practice to lock questions with an answer only if you are the first expert in the thread, or if all other comments are evidently wrong. Otherwise it is usual to post a *comment* only. This way the questioner can later choose easily which expert helped most. Thank you for listening...   (-:

Regards, Madshi.
0
traustiAuthor Commented:
I need an example with createprocess thanks
0
intheCommented:
var
  ds: Pchar;
  i: Integer;
  si :TStartupInfo;
  sa :PSecurityAttributes;
  ppi :PProcessInformation;
  pi  :TProcessInformation;
  h : LongBool;
begin
 ds:=PChar('');
 sa:=nil;
 GetStartupInfo(si);
 h:=CreateProcess( PChar('C:\Windows\Notepad.exe),
                   PChar(''),
                   sa,
                   sa,
                   false,
                   0,
                   ds,
                   PChar('C:\Windows'),
                   si,
                   pi
                   );
 if not h then showmessage('an error occurred') else
 begin
 WaitForSingleObject(pi.hProcess,10000);
 showmessage('finished');
 end;
close;
end;




0
intheCommented:
but that wont let your program "breath",in fact quite the opposite WaitForSingleObject() waits until the notepad is finished before your code continues...
0
traustiAuthor Commented:
I need an example with createprocess thanks
0
traustiAuthor Commented:
I got this message

an error occurred

//if not h then showmessage('an error occurred') else

what is wrong?
0
intheCommented:
apart from an unterminated string here:

h:=CreateProcess( PChar('C:\Windows\Notepad.exe),
maybe change this:
PChar('C:\Windows')  to
PChar('C:\')  
 
                   
there should be no error,i tested and works ,you can tell when it works becuase my test app doesnt even repaint itself...
maybe you have older version of delphi and need to change declaration?what delphi version you have?

i really dont think this is what your after is it?
dont you want your app to continue doing its stuff or you want your app to stop completely and wait for new app to finish?


0
traustiAuthor Commented:
okey, thi works, my code was like this

h:=CreateProcess( PChar('Notepad.exe'),
                                                    maybe change this:
                                                    PChar('C:\winnt')  to
                                                    PChar('C:\')  
------------
alright!!! maybe you can help me with this stuff!!!

how is best to executes all values in listview?

my listview will have this values

Tasks                                    Description
-------------------------------------------------------------------
Run App:                               c:\winnt\notepad.exe
Wait:                                    10000 // 10 seconds
SendKeys:                             {ALT}fo
............
............
--------------------------------------------------------------------

so i want to run notepad, wait 10 seconds and then send "file open" to notepad and even more

0
traustiAuthor Commented:
okey, thi works, my code was like this

h:=CreateProcess( PChar('Notepad.exe'),
                                                    maybe change this:
                                                    PChar('C:\winnt')  to
                                                    PChar('C:\')  
------------
alright!!! maybe you can help me with this stuff!!!

how is best to executes all values in listview?

my listview will have this values

Tasks                                    Description
-------------------------------------------------------------------
Run App:                               c:\winnt\notepad.exe
Wait:                                    10000 // 10 seconds
SendKeys:                             {ALT}fo
............
............
--------------------------------------------------------------------

so i want to run notepad, wait 10 seconds and then send "file open" to notepad and even more

0
intheCommented:
now we get details ...

The WaitForSingleObject function returns when one of the following occurs:
1:The specified object is in the       signaled state.
2:The time-out interval elapses.

DWORD WaitForSingleObject(
    HANDLE hHandle,      // handle of object to wait for
    DWORD dwMilliseconds       // time-out interval in milliseconds  
   );

execute values from listview i never tried ..
0
traustiAuthor Commented:
can you give me hint, can i use a timer component or ?
0
intheCommented:
shouldnt need a timer just try calling

do something;
sleep(dwMilliSecs);
do somnething else;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
traustiAuthor Commented:
can you give me hint, can i use a timer component or ?
0
traustiAuthor Commented:
thanks
0
traustiAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.