Solved

Delphi Programming question

Posted on 1997-09-04
22
218 Views
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?

Thanks.

Tom.
0
Comment
Question by:tomcorcoran
  • 10
  • 6
  • 4
  • +1
22 Comments
 
LVL 2

Expert Comment

by:icampbe1
ID: 1343713
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
 

Author Comment

by:tomcorcoran
ID: 1343714
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
 
LVL 2

Expert Comment

by:icampbe1
ID: 1343715
Delphi 1  or  D2/3 ?
0
 

Author Comment

by:tomcorcoran
ID: 1343716
D1 - I mentioned that at the start, thanks.
0
 
LVL 2

Expert Comment

by:icampbe1
ID: 1343717
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
 

Author Comment

by:tomcorcoran
ID: 1343718
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
 

Author Comment

by:tomcorcoran
ID: 1343719
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
 
LVL 2

Expert Comment

by:icampbe1
ID: 1343720
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
 

Author Comment

by:tomcorcoran
ID: 1343721
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
 
LVL 3

Expert Comment

by:mirek071497
ID: 1343722
Do you waiting for the solution ?
0
 

Author Comment

by:tomcorcoran
ID: 1343723
Mirek, good to get your comment. Yes, Ian never got back again. The icon still does not appear in the taskbar. Tom.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 3

Expert Comment

by:mirek071497
ID: 1343724
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
 

Author Comment

by:tomcorcoran
ID: 1343725
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
 
LVL 3

Expert Comment

by:mirek071497
ID: 1343726
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
 
LVL 3

Expert Comment

by:mirek071497
ID: 1343727
Hi are you there ?
0
 

Accepted Solution

by:
cashew earned 90 total points
ID: 1343728
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
 

Author Comment

by:tomcorcoran
ID: 1343729
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
 
LVL 3

Expert Comment

by:mirek071497
ID: 1343730
Hi Tom. I see so you are there. Why you don't test my sugestions ?
0
 

Author Comment

by:tomcorcoran
ID: 1343731
Mirek,

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

Expert Comment

by:cashew
ID: 1343732
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
 
LVL 3

Expert Comment

by:mirek071497
ID: 1343733
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
 

Author Comment

by:tomcorcoran
ID: 1343734
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now