How to popup/activate a main window of application?
Posted on 2010-08-31
It is Borland Delphi 5 forms application.
I need to make application running a single instance only.
If user trying to start a new instance of application it should send parameters to the already running instance and then exit, while the running instance of application should popup the main form.
Note: it is a typical MDI forms application written in Borland Delphi 5, built with Run-time packages=Vcl50;Vcl50x.
To achieve this I'm using some communication protocol based on a SendMessage(HWND_BROADCAST, ...). This part is working fine - it finds the running instance, check if can reuse it, sends parameters to running instance and then exit. So, this part is ok.
But the biggest problem I have at the moment - it cannot popup/activate the Window of running app instance.
I have tried different ways, like this:
Self.BringToFront; // Self is a class derived from TForm
But no success :-(((
Always - it is only blinking in the Widnows taskbar but not activate the main form of application! :-\
Please help - how I can activate application window? I mean - it should bring to front and make active (not just flashing in a Windows taskbar).
Test scenario is following:
1) run MyApp.exe, it started, show the main form, working.
2) switch to Explorer (as option - FAR/TotalCommaner), start the new instance of MyApp.exe
3) The newly started MyApp.exe should exit, the MyApp.exe started on step (1) should bring to front main form, so it is active and user can just work with it.
Problem - step (3) does not work - instead it only blinking in a taskbar. So, it activated correct application but unable to popup main form.
PS. I'm testing it on Windows 7 x64, also on Windows 2000/XP/2003/2008 - in all OSes it behaving the same way.