Icon Tray Problem

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?
DougBAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
BoRiSConnect With a Mentor Commented:
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
 
DougBAuthor Commented:
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
 
delphiexpertCommented:
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
BoRiSCommented:
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
 
RomanianCommented:
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
 
viktornetCommented:
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
 
zacCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.