Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Icon Tray Problem

Posted on 1998-11-17
7
Medium Priority
?
227 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 400 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
Independent Software Vendors: 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

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.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

971 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