[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

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.
0
craig_capel
Asked:
craig_capel
  • 7
  • 4
1 Solution
 
florisbCommented:
is an autostart from the registry an option? (currentversion/run).

Floris.
0
 
craig_capelAuthor Commented:
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
 
MadshiCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
craig_capelAuthor Commented:
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
 
craig_capelAuthor Commented:
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
 
MadshiCommented:
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
 
craig_capelAuthor Commented:
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
 
MadshiCommented:
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
 
craig_capelAuthor Commented:
Adjusted points from 100 to 139
0
 
craig_capelAuthor Commented:
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
 
MadshiCommented:
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
 
craig_capelAuthor Commented:
Yeah you were correct :) thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now