Article View: borland.public.cppbuilder.nativeapi
Article #1051Re: TTrayIcon and Shutdown (one step later)
From: Marc
Date: Fri, 16 Nov 2007 06:32
Date: Fri, 16 Nov 2007 06:32
101 lines
4058 bytes
4058 bytes
Hi John
Thank you for your answer.
This could probably work, but then my application would call Windows to shut
down, not the user anymore.
The whole thing takes place when we are already in a shutdown sequence. The
problem is that somehow the sequence is interrupted and Windows does not
complete it. So rather than a way of restarting a new shutdown sequence I
was looking for a way to complete the initial shutdown sequence started by
the user.
Rds
Marc
"JohnC" <jcibulskis@sbcglobal.net> schrieb im Newsbeitrag
news:473cdc5d@newsgroups.borland.com...
> 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:
<473d39cd$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!eweka.nl!lightspeed.eweka.nl!194.134.4.77.MISMATCH!news2.euro.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<473cd9cf$1@newsgroups.borland.com> <473cdc5d@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 Reply-To: "Marc" <info@mawnet.com> From: "Marc" <info@mawnet.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <473cd9cf$1@newsgroups.borland.com> <473cdc5d@newsgroups.borland.com> Subject: Re: TTrayIcon and Shutdown (one step later) Date: Fri, 16 Nov 2007 07:32:54 +0100 Lines: 103 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: 83.76.16.227 Message-ID: <473d39cd$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1195194829 83.76.16.227 (15 Nov 2007 22:33:49 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!eweka.nl!lightspeed.eweka.nl!194.134.4.77.MISMATCH!news2.euro.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail