We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


Delphi Programming question

boardtc asked
Medium Priority
Last Modified: 2010-04-04
If you create and show a form in the project source in D1 prior to creating your main form an icon does not apear in the taskbar. I need to do this for mo login screen but would like an icon to appear - any ideas?


Watch Question

You should be aware that the app isn't picking messages ffrom the queue at that point.  I would try either:

Application.ProcessMessages  right after you create your first form


Application.Icon := SomeIcon;  {Assuming that's what you mean to do}

Then let the project continue with the rest of the creates.

Hope this helps,

Ian C.


Ian, Thanks for the reply. This sounded like it was the solution. I tried both suggestions (made sure the application.icon was being set) but neither worked. Have you tried this succesfully?
Thanks. Tom.

Delphi 1  or  D2/3 ?


D1 - I mentioned that at the start, thanks.

Sorry, I've been really busy and haven't had a chance to do much here at this site.  Ok, give this a shot...

CONST  WM_SETICON = 128;   {Isn't defined anywhere in 16 bit Delphi}

  Application.Icon := Icon;

  Self.Perform( WM_SETICON, 1, Icon.Handle );  {Self is main form in my case}
  SendMessage(Application.Handle, WM_SETICON, 1, Icon.Handle);

Let me know if t his does it...   I'll post this as a comment...

Ian C.



Superb man. I did the following:

   { creating form in project source prior to main form }
   with TfrmLogin.Create(Application) do
         { sets icon for windows95 taskbar }
         LoadIconFromRes(APPICON, Application.Icon);
         Perform(WM_SETICON, 1, Application.Icon.handle);
         SendMessage(Application.Handle,WM_SETICON, 1,                      Application.Icon.handle);
         if (ShowModal = mrCancel) then Exit;

LoadIconFromRes is one of my utility functions. So perform sends the message straight to the window just created (without this line won't be in taskbar but will be seen by alt-tab) and then you pass the same message to the application. I'm not sure I understand it fully.

Set it up so I can grade you. Thanks a million.




Actually I got it wrong. In the above code, perform doesn't seem to do anything, sendmessage on it's own created an icon seen by alt-tab but not on the taskbar. Assigning a seperate icon as:

         ico := TIcon.Create;
         LoadIconFromRes(APPICON, ico);
         Application.Icon := ico;
         Perform(WM_SETICON, 1, Ico.handle);
         SendMessage(Application.Handle,WM_SETICON, 1,          Ico.handle);

has the same effect. So it seems we are half way there, just the taskbar to go. Thanks a million for the help - there's no worries giving you more points.


Hi Tom,

OK, lets get serious here, hmmm.....  Using the example directly above, put the following right after the SendMessage(.....

RedrawWindow( Application.Handle, NIL, 0,  RDW_INVALIDATE + RDW_FRAME );

While we're going through all of this, remember that window messages aren't being picked from the message queue yet.  So for every test you do, through in a Application.ProcessMessages to further explore your test.

Keep smiling,
Ian C.


Ian, I tried exactly the above with no difference, the icon is still not appearing in the taskbar. Am I missing something? Thanks. Tom.

Do you waiting for the solution ?


Mirek, good to get your comment. Yes, Ian never got back again. The icon still does not appear in the taskbar. Tom.
Try this example :

program Project1;

  Unit1 in 'UNIT1.PAS' {Form1},
  Unit2 in 'UNIT2.PAS' {Form2},
  Unit3 in 'UNIT3.PAS' {Form3};

{$R *.RES}

  WM_SETICON = 128;

{ create first form with you'r login to see them in taskbar }
  Form2 := TForm2.Create( Application );
{ change Application icon }
  Form2.Perform( WM_SETICON, 1, Form2.Icon.Handle );
  SendMessage(Application.Handle, WM_SETICON, 1, Form2.Icon.Handle);
{ Show Login Form }
{ this is normal }
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm3, Form3);
{ before running assign Mainform icon to Application }
  Form1.Perform( WM_SETICON, 1, Form1.Icon.Handle );
  SendMessage(Application.Handle, WM_SETICON, 1, Form1.Icon.Handle);

You'r problem was probably with creating and showning You'r Login Form.



Thanks for the example. Have you tested this code? The important code is prioe to the Form2.ShowModal, at this point one checks to see if the icons are in the taskbar. One of the problems with the example is that an icon is never assigned, that's the only difference to the exampe I showed prior. Therefore an Alt-Tab show the fedault MS icon for the application and nothing appears in the taskbar. Tom.

[If you do not (don't) mind me saying, you should write "your" instead of "you'r". "you're" is short for "you are", whearas "your" is possesive as in "your login form" !]
Hi Tom. I try this example and then send as comment. This works ! (After Alt-Tab and in TaskBar)
Try made simple project with my sugestions, mayby you have other error in you'r code. I made the two forms and in property Icon I assign 2 different icons from examples.
I read before so you use LoadIconFromRes, mayby there is the mistake.

BTW default icon after (Alt-Tab apears when you have not the WM_SECTION section, and default icon on TaskBar apears when you don't have icon assigned to form property;

Very Thanks for your correction about english.
Hi are you there ?
It appears that the "extra" form that you need displayed, must be displayed before the main form, and that this extra form is just the login screen, correct?  If that's the case, I do the same thing.

Set the OnShow property of the main form to call a procedure.  At this point, the form has been created, the Icon shows up on the task bar, but the main form is not yet visible.  In the OnShow procedure, you can call your password logon form either by calling a dialog procedure that handles the application.CreateForm(TMyForm, MyForm), or if it is already created by default, then just MyForm.ShowModal.

In any event, as soon as this other form is gone (modal exit), then the actual display of your main form kicks in.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Cashew, thanks for the answer. I'm not sure that would work. How would you exit from the mainform's OnShow cleanly (D1), ie. not showing a flash of the form, if the user decides to cancels from the login screen?

Hi Tom. I see so you are there. Why you don't test my sugestions ?



I am not sure what to try - it seems the same as before...

Tom -
   There is no problem with exiting the OnShow.  If the user cancels or enters an invalid password, then exit the application.  If the password is fine, then do nothing.  The password dialog will go away on its own, and the Main form will be displayed on its own as soon as the OnShow completes out the bottom.
   The MainForm will not have been displayed AT ALL until such time as the OnShow completes.  The only addition I would make, is that your password dialog call be a function that returns whether the answer was valid, so that when back in OnShow, you can decide whether to do nothing (and show MainForm), or exit application.
   TRY IT.  I use this technique for three different apps with no trouble, and it takes VERY little code.  Wherever possible, let Delphi do the work for you.
   If you don't know what to try, then try then try all suggestions in any order and learn from them by example.  Goodness knows I learned a lot that way...  it just takes a lot of experimental learning.
Hi tom. I don't need your points. I try to help you. I wrote later so this code works for me and I submit this after testing. Mayby you have some other mistake. Please Create New simple project and try.


Mirek, Thanks, I'm not saying I don't appreciate your efforts. I haven't seen a difference in what you are saying to try but I will try and make some time today to test another project. Cashew, I have tries all this stuff many times, that was why I went to showing it prior to creating the main form, if they cancel the login I need to shut down the main form without showing/flashing, in D2+ this can be done nicely with setting the showmainform variable, in Delphi 1.0 it's a problem. I have got around this in other projects by not autocreating any form, not even the main form as follows, but in this projects it's not feasible for me, so hence I went to the creating prior to the main form, which is the solution - Mirek, I will get back to you later:

{ set abortApp if need to abort showing }

   frmMain := TfrmMain.Create(nil);
      if not frmMain.abortApp then begin
         until not frmMain.Visible;

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.