Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Keep a program active

Posted on 2000-03-30
12
Medium Priority
?
162 Views
Last Modified: 2010-04-04
this is what i want to happen....

I have a little form that is stuck in the top right corner of the screen (with date and time), but i need to keep it there, even when the user has logged off, so when you you log back in again, the form is there, i have seen something like this before...., i do not need it invisible, sine the user has to see the form, i just want it to not close down when the user logs off....

i have delphi 4....

registerservices, and it when i logged off, my form would aways get closed down..... did i see this done, or was i dreaming?...

Thanks All....

Craig C.
0
Comment
Question by:craig_capel
[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
  • 4
12 Comments
 
LVL 2

Expert Comment

by:florisb
ID: 2668681
is an autostart from the registry an option? (currentversion/run).

Floris.
0
 
LVL 2

Author Comment

by:craig_capel
ID: 2668731
no no, you mean runservices, nope....

You have a form on the screen.... you can see it.... you go Start Log Off username...

(Windows 98)...

Enter Username:
Enter Password:

In the top right corner, you should still see my program, i simply do not want it to close down...

closequery, canclose:=false; stops it from shutting down totally, i need it to just carry on with it closing down, sure when they hit reset, then yeah put it into the registry........
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2669375
RegisterServiceProcess is only the half of the solution. The other half comes here:

type TMainFormHookObj = class (TObject) function MsgHook(var Msg: TMessage) : boolean; end;
var  MainFormHookObj  : TMainFormHookObj = nil;

function TMainFormHookObj.MsgHook(var Msg: TMessage) : boolean;
begin
  result := (Msg.Msg = WM_ENDSESSION) and (Msg.lparam <> 0);
end;

  MainFormHookObj := TMainFormHookObj.Create;
  Application.HookMainWindow(MainFormHookObj.MsgHook);

We have to use this hack, since Delphi doesn't handle the WM_ENDSESSION correctly.

Now your program should stay alive, but I guess it's hidden while the user logs on. Hidden, but not shut down...

Regards, Madshi.
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 2

Author Comment

by:craig_capel
ID: 2669522
Nope, My honest intentions are..... To be able to create a Clock that can be seen when the user logs off..... My old College allows you to log off then enter your unique username ready for the next person, i would like to be able to see the clock without having to login back in again.... Even though i am now living 2300 miles away from England and now living in Tenerife, i can use the same rules here :)....

I will give it a Try, thanks for your help Madshi... if it works, you get the points....

Craig C.
0
 
LVL 2

Author Comment

by:craig_capel
ID: 2669626
I'm Really Lost now...

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
   TMainFormHookObj = class (TObject);
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
       function MsgHook(var Msg: TMessage) : boolean;
  public
    { Public declarations }
  end;



var
  Form1: TForm1;
  MainFormHookObj: TMainFormHookObj = nil;

implementation

{$R *.DFM}

Function tform1.MsgHook(var Msg: TMessage) : boolean;
 begin
  result := (Msg.Msg = WM_ENDSESSION) and (Msg.lparam <> 0);
 end;

procedure TForm1.FormCreate(Sender: TObject);
begin

MainFormHookObj := TMainFormHookObj.Create;
  Application.HookMainWindow(MainFormHookObj.MsgHook);

end;

end.


am i getting closer?...
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2669843
Nope...   :-)

Just use the code that I posted. Don't change anything. Additionally you have to use RegisterServiceProcess.

I'm not sure whether your program will be visible during logon. You'll have to try that.

Regards, Madshi.
0
 
LVL 2

Author Comment

by:craig_capel
ID: 2670615
One last attempt.... I really am being honest, I want my program in FULL view so people can see it all the time, 100% of the time, never go invisible....
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2670687
Yes, I know what you want. Try my code (together with RegisterServiceProcess). It keeps your program running while the user logs off and on. I'm just not sure, whether it will be visible during the logon box is shown. I don't know, try it.
BTW, you should probably start your program in the RunServices key.
0
 
LVL 2

Author Comment

by:craig_capel
ID: 2676278
Adjusted points from 100 to 139
0
 
LVL 2

Author Comment

by:craig_capel
ID: 2676279
ok ok, my attempts have failed..... I tried your code, but no luck for me, has it got anything to do with D4? pretty please with sugar on top, can i have the code with the rest like uses and stuff, i am completey lost
0
 
LVL 20

Accepted Solution

by:
Madshi earned 556 total points
ID: 2677450
Well, what was so difficult with it? I tried it in 2 minutes and it works perfectly - exactly like you wanted it.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

type TMainFormHookObj = class (TObject) function MsgHook(var Msg: TMessage) : boolean; end;
var  MainFormHookObj  : TMainFormHookObj = nil;

function TMainFormHookObj.MsgHook(var Msg: TMessage) : boolean;
begin
  result := (Msg.Msg = WM_ENDSESSION) and (Msg.lparam <> 0);
end;

procedure TForm1.FormCreate(Sender: TObject);
const RSP_SIMPLE_SERVICE     = 1;
      RSP_UNREGISTER_SERVICE = 0;
var RegisterServiceProcess : function (processID: cardinal; flags: integer) : integer; stdcall;
begin
  RegisterServiceProcess := GetProcAddress(GetModuleHandle(kernel32), 'RegisterServiceProcess');
  RegisterServiceProcess(0, RSP_SIMPLE_SERVICE);
  MainFormHookObj := TMainFormHookObj.Create;
  Application.HookMainWindow(MainFormHookObj.MsgHook);
end;

end.

Regards, Madshi.
0
 
LVL 2

Author Comment

by:craig_capel
ID: 2677851
Yeah you were correct :) thanks
0

Featured Post

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!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

618 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