ExitWindowsEx + LOGOFF + WINDOWS 95 = SUCCESS!!!

-------------------------------------------------------------
                    DE  DIGITALE  STAD

Op Thu, 7 Aug 1997 cw...@{*word*104}station.net schreef:

Quote
> I finally got a Delphi program to call
> ExitWindowsEx and properly do a LOGOFF
> for both Windows 95 and NT 4.0
> AND exit itself without having to resort
> to any bizzare stuff like manually creating
> a separate thread in which to run the call to
> ExitWindowsEx or anything like that. (Now whether
> Delphi creates a thread itself to do this.... I
> have no idea, but here's how I did it.

> 1) create a simple little SDI app that paints one
> form which contains some text objects to let the
> user know what's going on.

> 2) select the 'view source' option and my main prog
> looks like this:

> program ADIOS;

> uses
>   Windows,
>   Forms,
>   Sdimain in 'SDIMAIN.PAS' {XLogoff};

> {$R *.RES}

> CONST EWX_LOGOFF = 0;
> CONST EWX_SHUTDOWN = 1;
> CONST EWX_REBOOT = 2;
> CONST EWX_FORCE = 4;
> CONST EWX_POWEROFF = 8;

> begin {MAIN}
>   Application.Title := Network Logoff';
>   Application.CreateForm(TXLogoff, XLogoff);
>   Application.Run;
>   Application.Terminate;
>   If (ExitWindowsEx(EWX_LOGOFF,0)) THEN;
>   exit;
> end. {MAIN}

> 3) My SDIMAIN unit looks like this:

> unit Sdimain;

> interface

> uses Windows, Classes, Graphics, Forms, Controls,
>    StdCtrls, ExtCtrls, ComCtrls;

> type
>   TXLogoff = class(TForm)
>     Label1: TLabel;
>     Label2: TLabel;
>     Label3: TLabel;
>     procedure FormCreate(Sender: TObject);
>   private
>     { Private declarations }
>   public
>     { Public declarations }
>   end;

> var
>   XLogoff: TXLogoff;

> implementation

> {$R *.DFM}

> procedure TXLogoff.FormCreate(Sender: TObject);
> begin
>   Application.Terminate;
> end;

> END.

> Somehow the two Application.Terminate's (one in main,
> the other in Form.Create)are necessary for this program
> to shut itself off under Win95 after shutting everything
> else off. I dunno why...., it just made my brain hurt.
> I'm just satisfied that this steeking program now does what
> I need it to do. I could probably shrink the size down by
> getting rid of unneeded "uses" stuff, but I'm afraid to dink
> with it anymore =8-o.

> If anybody else out there can use this monster, then cheers.

> peace,
> Neal

> -------------------==== Posted via Deja News ====-----------------------
>       http://www.dejanews.com/     Search, Read, Post to Usenet

This will only work under NT if you have the rights. Usually, you don't.

     Igmar