🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Creating / mimicing the XP shutdown grey fade...

#3951
From: JD
Date: Thu, 06 Apr 2006 23:32
189 lines
7744 bytes
"Mike Collins" <its@TheBottomOfThePost.com> wrote:
>

It doesn't fade the image but I think it could with what Bob
posted and a timer:

//-------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TGrayedForm *Dummy = new TGrayedForm( this );
    Form2->ShowModal();
    delete Dummy;
}
//-------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
    TGrayedForm *Dummy = new TGrayedForm( this );
    bool Result = OpenDialog1->Execute();
    Form2->ShowModal();
    delete Dummy;
    if( Result )
      {
          //
      }
}
//-------------------------------------------------------------


//-------------------------------------------------------------
#ifndef GrayedFormH
#define GrayedFormH
//-------------------------------------------------------------
#include <Classes.hpp>
#include <ExtCtrls.hpp>
//-------------------------------------------------------------
#define UWM_INITIALIZE (WM_USER + 100)
//-------------------------------------------------------------
class TGrayedForm : public TPanel
{
    protected:
        virtual void __fastcall PaintWindow(HDC DC);
        virtual void __fastcall WndProc( TMessage &Message );
        virtual void __fastcall NewFormWndProc( TMessage &Message );
    private:
        typedef TPanel inherited;
        TForm *pForm;
        Graphics::TBitmap* Bmp;
        TList* NCControlList;
        TWndMethod SaveFormWndProc;
        void __fastcall NCPaint();
    public:
        __fastcall  TGrayedForm( TComponent *Owner );
        __fastcall ~TGrayedForm();
};
//-------------------------------------------------------------
#endif


//-------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "GrayedForm.h"
#pragma package(smart_init)
//-------------------------------------------------------------
__fastcall TGrayedForm::TGrayedForm( TComponent *Owner ) : TPanel( Owner )
{
    pForm = dynamic_cast<TForm*>( Owner );
    if( !pForm ) throw Exception("TGrayedForm : Owner is not a TForm." );
    Parent = pForm;
    Visible = false;
    BevelOuter  = bvNone;
    BevelInner  = bvNone;
    Left = 0;
    Top = 0;
    Align = alClient;
    Bmp = NULL;
    NCControlList = NULL;

    Application->ProcessMessages();

    Bmp = new Graphics::TBitmap;
    Bmp->Width       = pForm->Width;
    Bmp->Height      = pForm->Height;
    Bmp->PixelFormat = pf24bit;
    HDC hDC = ::GetWindowDC( pForm->Handle );
    ::BitBlt( Bmp->Canvas->Handle, 0, 0, pForm->Width, pForm->Height, hDC, 0, 0, SRCCOPY );
    ::ReleaseDC( pForm->Handle, hDC );

    BYTE R,G,B,L,*ScanLine;
    for( int y = 0; y < Bmp->Height; ++y )
      {
          ScanLine = static_cast<BYTE*>( Bmp->ScanLine[y] );
          for( int x = 0; x < Bmp->Width; ++x )
            {
                R = ScanLine[ x * 3 + 0 ];
                G = ScanLine[ x * 3 + 1 ];
                B = ScanLine[ x * 3 + 2 ];
                L = (BYTE)((R * 0.299) + (G * 0.587) + (B * 0.114));
                ScanLine[ x * 3 + 0 ] = L;
                ScanLine[ x * 3 + 1 ] = L;
                ScanLine[ x * 3 + 2 ] = L;
            }
      }

    SaveFormWndProc = pForm->WindowProc;
    pForm->WindowProc = NewFormWndProc;
    pForm->Enabled = false;

    ::PostMessage( Handle, UWM_INITIALIZE, 0, 0 );
}
//-------------------------------------------------------------
__fastcall TGrayedForm::~TGrayedForm()
{
    delete Bmp;
    if( NCControlList )
      {
          for( int x = 0; x < NCControlList->Count; ++x )
            {
                TWinControl *pControl = static_cast<TWinControl*>( NCControlList->Items[x] );
                pControl->Visible = true;
            }
          delete NCControlList;
      }
    pForm->WindowProc = SaveFormWndProc;
    pForm->Enabled = true;
}
//-------------------------------------------------------------
void __fastcall TGrayedForm::NewFormWndProc( TMessage &Message )
{
    if( Message.Msg == WM_NCPAINT ) NCPaint();
    else SaveFormWndProc( Message );
}
//-------------------------------------------------------------
void __fastcall TGrayedForm::PaintWindow(HDC DC)
{
    TRect R;
    ::GetWindowRect( Handle, &R );
    ::OffsetRect( &R, -pForm->Left, -pForm->Top );
    Canvas->CopyRect( Rect(0, 0, Width, Height), Bmp->Canvas, R );
}
//-------------------------------------------------------------
void __fastcall TGrayedForm::NCPaint()
{
    TRect R;
    ::GetWindowRect( Handle, &R );
    HDC hDC = ::GetWindowDC( pForm->Handle );
    R = Rect( 0, 0, pForm->Width, R.Top - pForm->Top );
    ::BitBlt( hDC, R.Left, R.Top, R.Right, R.Bottom, Bmp->Canvas->Handle, R.Left, R.Top, SRCCOPY );
    R = Rect( 0, R.Bottom, ::GetSystemMetrics(SM_CXFRAME), pForm->Height );
    ::BitBlt( hDC, R.Left, R.Top, R.Right, R.Bottom, Bmp->Canvas->Handle, R.Left, R.Top, SRCCOPY );
    R = Rect( pForm->Width - ::GetSystemMetrics(SM_CXFRAME), R.Top, pForm->Width, R.Bottom );
    ::BitBlt( hDC, R.Left, R.Top, R.Right, R.Bottom, Bmp->Canvas->Handle, R.Left, R.Top, SRCCOPY );
    R = Rect( ::GetSystemMetrics(SM_CXFRAME), pForm->Height - ::GetSystemMetrics(SM_CYFRAME), pForm->Width - ::GetSystemMetrics(SM_CXFRAME), R.Bottom );
    ::BitBlt( hDC, R.Left, R.Top, R.Right, R.Bottom, Bmp->Canvas->Handle, R.Left, R.Top, SRCCOPY );
    ::ReleaseDC( pForm->Handle, hDC );
}
//-------------------------------------------------------------
void __fastcall TGrayedForm::WndProc( TMessage &Message )
{
    if( Message.Msg == UWM_INITIALIZE )
      {
          // need to handle TWinControls that steal from client area
          // to simulate that they're part of the non-client area
          NCControlList = new TList();
          for( int x = 0; x < pForm->ComponentCount; ++x )
            {
                TWinControl *pControl = dynamic_cast<TWinControl*>( pForm->Components[x] );
                if( pControl )
                  {
                      TRect R;
                      ::GetWindowRect( pControl->Handle, &R );
                      TPoint P = Point( 0, 0 );
                      P = ClientToScreen( P );
                      if( P.y >= R.Top )
                        {
                            pControl->Visible = false;
                            NCControlList->Add( pControl );
                        }
                  }
            }
          Visible = true;
          NCPaint();
      }
    inherited::WndProc( Message );
}
//-------------------------------------------------------------

~ JD
Technical Details
Message-ID: <4435a4f8@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <442b1df3$1@newsgroups.borland.com> <442bbd3f$1@newsgroups.borland.com> <442cdc46$1@newsgroups.borland.com> <44315fae$1@newsgroups.borland.com> <44351e8d@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,ff65259e4dac42c3
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "JD" <nospam@nospam.com>
Sender: "JD" <nospam@nospam.com>
Reply-To: "JD" <nospam@nospam.com>
Subject: Re: Creating / mimicing the XP shutdown grey fade...
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 152.163.100.201     
X-Forwarded-For: 172.157.31.145
References:  <442b1df3$1@newsgroups.borland.com> <442bbd3f$1@newsgroups.borland.com> <442cdc46$1@newsgroups.borland.com> <44315fae$1@newsgroups.borland.com> <44351e8d@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <4435a4f8@newsgroups.borland.com>
Date: 6 Apr 2006 16:32:08 -0700
X-Trace: newsgroups.borland.com 1144366328 207.105.83.66 (6 Apr 2006 16:32:08 -0700)
Lines: 190
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail