Solved

Icon Tray Problem

Posted on 1998-11-17
7
225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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