Solved

Icon Tray Problem

Posted on 1998-11-17
7
219 Views
Last Modified: 2010-04-04
I have an app that starts up in the icon tray.  When the app starts, I want to show a password screen.  If they enter the correct password, then bring the main form up, else keep it in the icon tray.  Any suggestions?
0
Comment
Question by:DougB
7 Comments
 

Author Comment

by:DougB
Comment Utility
I have to keep the main form the startup form because of the icon tray.  I can't create a form at create time of the main form, and if I do it OnShow of the main form (start the main form visible), I can't turn it invisible if they do not know the password...
0
 
LVL 1

Expert Comment

by:delphiexpert
Comment Utility
Doug,
does this help at all?

if PasswordIsCorrect then
  begin
  Application.Restore;
  Application.BringToFront;
  RemoveIconFromTray; // obviously put whatever code is needed here, it depends on how you implemented the tray icon.
  end else DoWhatever;


0
 
LVL 4

Accepted Solution

by:
BoRiS earned 200 total points
Comment Utility
DougB

Why don't you use a popup menu asigned to the icon in the systray if they choose to open the form form the popup menu then popup a second form with the password required  if the password is correct then show the main form if the password is incorrect then hide then hide the form or exit;

this is the popupmenu items on the trayicon

procedure TForm1.Open1Click(Sender: TObject);
begin
 Form2.Show;
end;

procedure TForm1.Exit1Click(Sender: TObject);
begin
 Close;
end;

this is the procedure of the button to check for the password on form2

procedure TForm2.Button1Click(Sender: TObject);
var
Password: string;
begin
 Password := 'letmein';
  if Edit1.Text = Password then
   Form1.Show
  else
    Form2.Hide;
end;

The password can be hard coded as above or you can save the password to the registry or inifile alowing the user to change the password they want...

Later
BoRiS

0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 4

Expert Comment

by:BoRiS
Comment Utility
DougB

another way is to place something like this in the project source...

program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2},
  Unit3 in 'Unit3.pas' {Password Form};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm3, Form3);
  Form3.Show;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.ShowMainForm := False;
  Form3.Update;
  Application.Run;
end.

Create the Form and pass the button1click from form2 example I gave you, what will happen is that the application will start create the form3 and show it then create your main form and hide it your icon will stay the same etc...

Try this if you want I will mail you a complete example just leave your mail address...

Later
BoRiS
0
 
LVL 1

Expert Comment

by:Romanian
Comment Utility
Make main form as Secure form, place on it TTrayIcon component and after correct password entered call CreateNewMainForm. In TTrayIcon component onClick event will show your main form.
if you want I'd send sample code.

PS: If you don't have TTrayIcon component I'd send it you too.
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
Just to give you an idea... Keep the password in a very secret place and be sure to encrypt it with a difficult to decrypt algorithm...otherwise your pgoram would be very easily cracked ...

The example Boris gave you with

if edit1.text = 'Hello' then DoEverythingIsKewl;

will be very easy to crack, so create a good algorithm :)

Otherwise, the code Boris gave you for showing forms and stuff is correct :)

Cheers,
Viktor
0
 
LVL 1

Expert Comment

by:zac
Comment Utility
DougB,

The way to do it in my opinion is to have a separate password dialog called class name TPassDlg (for instance).  But in project->options you remove it from the auto creation list.

Then when someone clicks you icon rather than showing the main form you do something like..


IconClickHandler.... - Or Called from the OnCreate of MainForm

var
  myDlg : TPassDlg;
begin
  myDlg := TPassDlg.Create(nil);
  try
    if myDlg.ShowModal = mrOK then
    begin
      // Check the password...
      if myDlg.PassEdit = 'mypassword' then
        MainForm.Show; // Or whatever to show the mainform.
    end;
  finally
    mydlg.Free;
  end;
end;


NOTE that this is just a very simple example and that it does *no* checking of whether your main form is already open etc....  However the principal is sound.

Also note that depending upon how your trayicon works you will either minimize or hide your application which will be done within the MainForm OnCreate handler using either:

Application.Minimize

OR

Application.Hide

The key here is that you use Create(nil)

The nil parameter means that the window belongs to the windows desktop - ie its a top level window and therefore is not hidden when the application (main form) is hidden.

If you have any further questions, let me know.

Good luck

Zac
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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

12 Experts available now in Live!

Get 1:1 Help Now