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
Solved

Keep a program active

Posted on 2000-03-30
12
149 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
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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 139 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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