Solved

Icon Tray Problem

Posted on 1998-11-17
7
221 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
ID: 1347169
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
ID: 1347170
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
ID: 1347171
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 4

Expert Comment

by:BoRiS
ID: 1347172
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
ID: 1347173
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
ID: 1347174
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
ID: 1347175
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
proper way to parse url in delphi 2 194
calling Tcolordialog in dll make the form disappear 8 111
Best Firemonkey component pack 1 101
Multi-layered image in FireMonkey 9 30
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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

18 Experts available now in Live!

Get 1:1 Help Now