Link to home
Start Free TrialLog in
Avatar of craig_capel
craig_capel

asked on

Keep a program active

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.
Avatar of florisb
florisb

is an autostart from the registry an option? (currentversion/run).

Floris.
Avatar of craig_capel

ASKER

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........
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.
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.
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?...
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.
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....
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.
Adjusted points from 100 to 139
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
ASKER CERTIFIED SOLUTION
Avatar of Madshi
Madshi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yeah you were correct :) thanks