Link to home
Start Free TrialLog in
Avatar of trausti
trausti

asked on

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
Avatar of Madshi
Madshi

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

Regards, Madshi.
I think he wants to call Winexec first and then minimize his application. Earm... Madshi... you're damnd fast with you replys! <g>
Avatar of trausti

ASKER

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 ??????
Oh... I forgot. Did you tried

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

?
Oh, sorry. Dont use Winexec, use ShellExecute instead. You can specify a parameter in the call (Win32 API) what should happen with your app.
Avatar of trausti

ASKER

!!!

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
Avatar of trausti

ASKER

!!!

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
Avatar of trausti

ASKER

have you example with ShellExecute
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.
shellexecute
('handle,'open',pchar('c:\acrobat4.exe'),nil,nil,sw_minimize);
application.processmessages;
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.
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.

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.
Avatar of trausti

ASKER

I need an example with createprocess thanks
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;




but that wont let your program "breath",in fact quite the opposite WaitForSingleObject() waits until the notepad is finished before your code continues...
Avatar of trausti

ASKER

I need an example with createprocess thanks
Avatar of trausti

ASKER

I got this message

an error occurred

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

what is wrong?
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?


Avatar of trausti

ASKER

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

Avatar of trausti

ASKER

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

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 ..
Avatar of trausti

ASKER

can you give me hint, can i use a timer component or ?
ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of trausti

ASKER

can you give me hint, can i use a timer component or ?
Avatar of trausti

ASKER

thanks
Avatar of trausti

ASKER

thanks