4
votes

I use delphi XE2. During my Main form OnCreate procedure I run some important elements, like login procedure and so on. My problem is, that when I show login form (invoked by OnCreate procedure), my application is not visible on TaskBar - it became visible when main form became visible. The problem is, that when user covered my login form by another application, without icon on taskBar he might not know that my application already runs and try to start it again. He must use ctrl+tab to get my application login form.

Now question... How to force application / OS to show application icon on Taskbar when OnCreate procedure is not finished?

regards Mario

3

3 Answers

11
votes

You can override the login form's CreateParams to include WS_EX_APPWINDOW ex-style.

type
  TLoginForm = class(TForm)
    ..

  protected
    procedure CreateParams(var Params: TCreateParams); override;
    ...

  end;

procedure TLoginForm.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
end;
1
votes

The taskbar button is shown when the window for the main form is created and visible. That happens after OnCreate. The simple solution is to show the login form later. The obvious choice would be OnShow. Make sure you only do that the first time OnShow fires.

Of course, this assumes that you want the main form to be visible whilst the login form shows. If not then you need to make sure that the login form has a taskbar button. Do that by making it unowned. Override CreateParams and set WndParent to 0. However, if you do that you'll get a taskbar button with the same title as the login form caption. And when the login form closes, that taskbar button will disappear, and the main form button will appear. You may not be pleased with how this looks.

I suppose you might try with Application.MainFormOnTaskbar set to False. Do that and the application window is the window behind the taskbar button. That's perhaps quite a drastic change. And I'm not 100% sure that a taskbar button will show if the main form is not showing, so this may be a dead end.

1
votes

You might want to check this answer of mine:

Delphi Change main form while application is running

In it I show a bit different aproach of how to implement login form (which in my case is actually main form) and then worker form (which is what you have now as main form).

Main advantages of my approach:

  • Becouse worker form is created after the sucsessfull login it alows you to easily dynamicaly create custom component layour based on the specific user creditentials (different levels of access)
  • It alows you an easy way for loggin off the current user without the need for closing the entire application. This is posible becouse worker form is not the applications main form and thus can be destroeyed anytime without causing application termination. And login forms which is the applications main form is only hidden during the time when certain user is logged in.