Jump to content
KodeZwerg

Solved: Application Run Check and bring to foreground

Recommended Posts

Hello, i am interested in having one of my Apps just run once.

I searched web for solutions that help me.

David Heffernan wrote here a really good example that covers my needs.

(have just one app running with ability to send commandline to loaded process)

 

My Application has trayicon status and wont come up with that code.

 

Can someone help me to extend its code that also trayicon will be restored, that would be great!

(i do use Delphi2010 if it matters)

Share this post


Link to post

Hi Code-Dwarf 😉

 

well, I think divide and conquer is the best thing.

 

Problems:

a) Detect that an other instance is already running

b) Make message transfer possible between this Apps

c) Properly transmit the own command line parameters 

d) Bring first instance to the front 

 

Questions:

What of this have you solved? 

Are these all problems that are list above?

 

Solutions (for me):

a) Mutex and Check for this

b) RegisterWindowsMessage -> For MessageID and HWND_BROADCAST to get an Handle for c)

c) WM_COPYDATA for Transmit command line data

d) Bring Application to the front and reshow

 

Hope this will help you

  • Like 1

Share this post


Link to post

Points a - c are checked

Point d is my misery,

If application is anywhere on screen it will show with Code from David properly.

If application is minimized to taskbar it will show with Code from David properly.

(Thankyou David for this good piece of code!)

If application is in systemtray, nothing happen there at all.

 

I will create a small Demo-Application that show my problem better (in fact this would be a 1;1 copy from Davids Post on StackOverflow)

 

Thankyou for help!

Share this post


Link to post

You just have to extend the code to bring itself out of the tray as you say. Although strictly speaking it isn't in the tray and in fact the tray isn't even called that. It's a notification icon in the notification area. 

 

What you mean by being in the tray is that the main form is hidden, Visible is false. So you just need to show it. Presumably you already do that when the notification icon handles being clicked. 

  • Thanks 1

Share this post


Link to post

@David HeffernanI show you where i did a mistake, now all works fluffy :-] and thank you for correcting my used words!

//      if IsIconic( Window ) then // <<<-- that was my mistake :-/
      ShowWindow( Window, SW_SHOW );

Thanks again to pointing it out!

 

If someone need, in attachment is a full working Binary and Source example ( Delphi 5 )

Should be compatible to all, just adjust the Namespace.

 

This demo show Davids excellent work added with Notification Area's Icon support  ( the WinApi way )

 

Updated source for more fun.

Added popup menu for notification icon

Renamed everything to its real stuff

Added small descriptions to Source

 

From my point of view it is final now.

 

 

OneApp.7z

Edited by KodeZwerg
corrected Tray Icon error in Source

Share this post


Link to post

Not sure if this helps, but the TJvAppInstances component in the JEDI VCL collection handles this quite nicely.

Share this post


Link to post

To all that liked Davids approach as I did -> I did updated above attachement, it should be final now ( I hope ).

If someone with more experience could take a look on, that would be really nice!

 

Thanks for reading.

 

@Nathan Wild to me not ( I do not have that ), others might find it useful, thanks for suggestion it.

Share this post


Link to post

Another update has been made.

I found a small bug and fixed it by porting the "ShowWindow()" into Forms Source and replacing with Vcl commands.

Now it demonstrate how to setup custom parameters to do some specific things.

 

Enjoy.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×