On 6/27/07, singh_chandra_bhan <[EMAIL PROTECTED]> wrote:
> I am having an application and I want that it should run only once.
> How can I do that ???
You could try and create a mutex, in your project source before
anything else. You can then check whether it failed because the mutex
already exists, and restore the existing app, and halt your program.
Example code below:
// Attempt to create a named mutex
CreateMutex(nil, false, 'TestApp');
// If it failed then there is another instance running
if GetLastError = ERROR_ALREADY_EXISTS then
begin
// Send all windows our cusom message, only other instance will
// recognise it and restore itself.
SendMessage(HWND_BROADCAST, RegisterWindowMessage('TestApp'), 0, 0);
// and relax!
halt(0);
end; // if