Thread View: borland.public.cppbuilder.nativeapi
4 messages
4 total messages
Started by DavideP
Wed, 24 Jan 2007 17:15
WinExec and multiple istances
Author: DavideP
Date: Wed, 24 Jan 2007 17:15
Date: Wed, 24 Jan 2007 17:15
15 lines
1408 bytes
1408 bytes
Hi everyone,
I've a little question.
I need to display a logfile of a program of mine, so I use:
WinExec('Notepad.exe C:\Temp\MyFile.txt', SW_SHOWDEFAULT);
on a OnClick event of a button.
It works well, but... by clicking several times on it I've found
multiple istances of Notepad opened...
How can I avoid this feature?
I need only one instance of notepad with my logfile.
Many thanks for the help.
Davide
Re: WinExec and multiple istances
Author: Remy Lebeau (TeamB)
Date: Wed, 24 Jan 2007 18:14
Date: Wed, 24 Jan 2007 18:14
31 lines
1947 bytes
1947 bytes
"DavideP" <no.spam@here.plz> wrote in message news:45b793fe@newsgroups.borland.com... > by clicking several times on it I've found multiple istances of Notepad opened... As you should be. That is how WinExec() works - it creates a new process each time it is called. > How can I avoid this feature? You can't. Notepad is not designed for that, and there is nothing WinExec() (or CreateProcess(), for that matter) can do about it. The called program, not the calling program, controls how the file is loaded. If the called program does not want to run multiple instances, then it has to control that on its own. The calling program has no say in that matter. > I need only one instance of notepad with my logfile. Then I suggest you not use Notepad at all. Display the log in your own UI, such as in a TMemo or TRichEdit control.. Then you have full control over it. If you must use an external program, then write your own. Then it can avoid multiple instances of itself. It is a very common feature to implement, so there are plenty of examples floating around to look at. Gambit
Re: WinExec and multiple istances
Author: Alberto
Date: Thu, 25 Jan 2007 19:52
Date: Thu, 25 Jan 2007 19:52
23 lines
1536 bytes
1536 bytes
DavideP wrote:
> Hi everyone,
> I've a little question.
>
> I need to display a logfile of a program of mine, so I use:
> WinExec('Notepad.exe C:\Temp\MyFile.txt', SW_SHOWDEFAULT);
> on a OnClick event of a button.
>
> It works well, but... by clicking several times on it I've found
> multiple istances of Notepad opened...
> How can I avoid this feature?
> I need only one instance of notepad with my logfile.
>
> Many thanks for the help.
>
> Davide
>
Just set a flag in your program... if WinExec has already been called,
ignore
the second pressure on that button.
You can reset that flag when the Notepad process terminates.
Alberto
Re: WinExec and multiple istances
Author: Alan Bellingham
Date: Fri, 26 Jan 2007 09:25
Date: Fri, 26 Jan 2007 09:25
21 lines
1908 bytes
1908 bytes
Alberto <dibene@usa.net> wrote: >Just set a flag in your program... if WinExec has already been called, >ignore >the second pressure on that button. >You can reset that flag when the Notepad process terminates. You could use a single handle onto the process. If the handle is already non-null, then it's running (or you've not yet checked its termination condition). If null, you've either never run it, or you've seen it terminate already and reset the handle to null. On the other hand, though this would technically work, it's unlikely to provide the probable required functionality of loading the latest log state. For this, a simple window with a simple edit control on it would be better. Alan Bellingham -- 10th Anniversary ACCU Conference: 11-14 April 2007 - Oxford, UK (Booking now open: see http://accu.org/index.php/conferences for details)
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads