Solved

Keep a program active

Posted on 2000-03-30
12
138 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
  • 7
  • 4
12 Comments
 
LVL 2

Expert Comment

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

Floris.
0
 
LVL 2

Author Comment

by:craig_capel
Comment Utility
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
Comment Utility
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
 
LVL 2

Author Comment

by:craig_capel
Comment Utility
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
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 2

Author Comment

by:craig_capel
Comment Utility
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
Comment Utility
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
Comment Utility
Adjusted points from 100 to 139
0
 
LVL 2

Author Comment

by:craig_capel
Comment Utility
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 139 total points
Comment Utility
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
Comment Utility
Yeah you were correct :) thanks
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now