🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #1050

Re: TTrayIcon and Shutdown (one step later)

#1050
From: JohnC
Date: Thu, 15 Nov 2007 23:55
80 lines
3310 bytes
Here's the whole thing:

//Note: This function was taken verbatim from the SDK documentation.
BOOL TForm1::MySystemShutdown()
{
   HANDLE hToken;
   TOKEN_PRIVILEGES tkp;

   // Get a token for this process.

   if (!OpenProcessToken(GetCurrentProcess(),
        TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
      return( FALSE );

   // Get the LUID for the shutdown privilege.

   LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
        &tkp.Privileges[0].Luid);

   tkp.PrivilegeCount = 1;  // one privilege to set
   tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

   // Get the shutdown privilege for this process.

   AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
        (PTOKEN_PRIVILEGES)NULL, 0);

   if (GetLastError() != ERROR_SUCCESS)
      return FALSE;

   // Shut down the system and force all applications to close.

   if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
      return FALSE;

   return TRUE;
}
//---------------------------------------------------------------------------

"Marc" <info@mawnet.com> wrote in message 
news:473cd9cf$1@newsgroups.borland.com...
> Hi all
>
> I read a lot about the TTrayIcon component and its problems with detecting 
> the WM_ENDSESSION with formless applications.
>
> So I took the source and modified the code in order to call an event in 
> the application in addition to simply call Shell_NotifyIcon(NIM_DELETE, 
> &FData).
>
> void __fastcall TMyTrayIcon::EndSession()
> {
>   OnEndSession(this);
>   Shell_NotifyIcon(NIM_DELETE, &FData);
> }
> //---------------------------------------------------------------------------
>
> In the OnEndSession event my application then does some cleanup and calls
> Application->Terminate();
>
> When running the application and log off, the WM_ENDSESSION is caught by 
> TMyTrayIcon, the OnEndSession event is fired and my application shuts down 
> correctly.
>
> But Windows does not continue with the shutdown...
>
> Does anyone have an idea why or how to get Windows to complete the shut 
> down (logoff)?
>
> This problem bugs me now for quite a while. I have tried alternatives like 
> the ShutDownWatcher but without success :-(
> Does anyone has a version of TTrayIcon that allows to define a shut down 
> event?
>
>
> Rds
> Marc
>
>
> 
Technical Details
Message-ID: <473cdc5d@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feed.tweaknews.nl!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <473cd9cf$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,a42b7d249fb2d6b7
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "JohnC" <jcibulskis@sbcglobal.net>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <473cd9cf$1@newsgroups.borland.com>
Subject: Re: TTrayIcon and Shutdown (one step later)
Date: Thu, 15 Nov 2007 17:55:09 -0600
Lines: 82
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 76.223.245.175
Message-ID: <473cdc5d@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1195170909 76.223.245.175 (15 Nov 2007 15:55:09 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feed.tweaknews.nl!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail