Delphi Programming question

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?

Thanks.

Tom.
boardtcAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

icampbe1Commented:
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

OR

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

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

Hope this helps,

Ian C.
0
boardtcAuthor Commented:
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.
0
icampbe1Commented:
Delphi 1  or  D2/3 ?
0
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

boardtcAuthor Commented:
D1 - I mentioned that at the start, thanks.
0
icampbe1Commented:
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.

0
boardtcAuthor Commented:
Ian,

Superb man. I did the following:

   { creating form in project source prior to main form }
   with TfrmLogin.Create(Application) do
      try
         { 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;
      finally
         Free;
      end;

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.

Tom.

0
boardtcAuthor Commented:
Ian,

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.

Tom.

0
icampbe1Commented:
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.


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


0
mirek071497Commented:
Do you waiting for the solution ?
0
boardtcAuthor Commented:
Mirek, good to get your comment. Yes, Ian never got back again. The icon still does not appear in the taskbar. Tom.
0
mirek071497Commented:
Try this example :

program Project1;

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

{$R *.RES}

const
  WM_SETICON = 128;

begin
{ 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 }
  Form2.ShowModal;
  Form2.Free;
{ 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);
  Application.Run;
end.

You'r problem was probably with creating and showning You'r Login Form.
0
boardtcAuthor Commented:
Mirek,

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" !]
0
mirek071497Commented:
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.
0
mirek071497Commented:
Hi are you there ?
0
cashewCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
boardtcAuthor Commented:
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?

Tom.
0
mirek071497Commented:
Hi Tom. I see so you are there. Why you don't test my sugestions ?
0
boardtcAuthor Commented:
Mirek,

I am not sure what to try - it seems the same as before...
0
cashewCommented:
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.
0
mirek071497Commented:
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.
0
boardtcAuthor Commented:
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);
   try
      if not frmMain.abortApp then begin
         frmMain.Show;
         repeat
            Application.HandleMessage;
         until not frmMain.Visible;
      end;
   finally
      frmMain.Free;
   end;

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.