Jump to content
TurboMagic

Double entry on taskbar

Recommended Posts

Hello,

 

I'm using D10.3.2 and this time I do something looking a bit strange. It works except for one thing.

I want to include sort of 2 applications (a main one and a small one sharing some code and the
language ressource dlls of the main one).

 

For this in the DPR I check if a certain command line parameter has been passed. If not the main app will
be started otherwise the small one. Here's some code:

 

Quote

var
  App: TApplication; // the normal Application variable is assigned to this one
                                   // as this prevents the IDE from messing around in the dpr
begin
  App := Application;

  App.Initialize;
  App.Title := 'MyApp';
  App.HelpFile := 'MyHelp.chm';
 
  if not ParamStr(1) = '/Test' then
  begin

    // calling the normal app works fine
    SetCurrentDir(ExtractFilePath(ParamStr(0)));

    App.CreateForm(TData, Data); // ein Datenmodul
    App.CreateForm(Tf_Main, f_Main);
  end
  else
  begin

    // calling the secondary app works, but produces a 2nd taskbar icon,
    // where does it come from and how to prevent?
    SetCurrentDir(ExtractFilePath(ParamStr(0)));

    App.Icon.LoadFromResourceName(HInstance, 'MyIcon');
    App.CreateForm(Tf_AlternateMain, f_AlternateMain);
  end;

  App.Run;
end.

 

So where does the 2nd taskbar icon in the one case come from and how to get rid of it?

 

Regards

TurboMagic

Share this post


Link to post

You are running 2 completely separate processes, and each one is creating its own TApplication window and a MainForm window, so of course there are going to be 2 separate Taskbar buttons, one for each process if those windows are visible.

 

If you don't want the user to interact with the windows, simply hide them.  Or, you can modify the window style of whichever window actually owns the Taskbar button (the TApplication window if TApplication.MainFormOnTaskbar=False, the MainForm window if TApplication.MainFormOnTaskbar=True) to remove the WS_EX_APPWINDOW style, then the window can't appear on the Taskbar even if the window is visible.  For the TApplication window, you would have to use (Get|Set)WindowLong/Ptr(GWL_EXSTYLE) directly for that.  For the TForm window, you can override its virtual CreateParams() method instead.

 

That being said, on Windows 7 and later at least, you can group related windows with their own Taskbar buttons together into a single Taskbar button by assigning the same Application User Model ID to all of the windows.  You can call SetCurrentProcessExplicitAppUserModelID() at the top of your DPR before any UI windows are created (you will likely have to set Application.MainFormOnTaskbar=True since the TApplication window gets created before the DPR code is run).  Or you can apply a AppUserModelID on a per-window basis via SHGetPropertyStoreForWindow() and IPropertyStore::SetValue(PKEY_AppUserModel_ID).

 

On a side note - Have a look at the FindCmdLineSwitch() function when searching for command-line parameters.

Edited by Remy Lebeau

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

×