🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#4007
From: JD
Date: Fri, 31 Mar 2006 06:37
141 lines
6726 bytes
"JD" <nospam@nospam.com> wrote:
>
>The final presentation of the screen is a simple gray-scale
>which is quite easy to mimic:

I peeked at the source today and it's only slightly more
complicated but it's also not mine to give you.

>    ::BitBlt( Bmp->Canvas->Handle, 0, 0, Width, Height, hDC, 0, 0, SRCCOPY );

After you grab the form's image (we did *not* use TForm's
GetFormImage method) and before you change the image to gray-
scale, you need to itterate the form's Components property
and paint those to the bitmap. For example:

    for( int x = 0; x < ComponentCount; ++x )
      {
          TWinControl *wControl = dynamic_cast<TWinControl*>( Components[x] );
          if( wControl )
            {
                HDC hDC = ::GetWindowDC( wControl->Handle );
                ::BitBlt( Bmp->Canvas->Handle,
                          wControl->Left + ::GetSystemMetrics(SM_CXFRAME),
                          wControl->Top + ::GetSystemMetrics(SM_CYCAPTION) + ::GetSystemMetrics(SM_CYFRAME),
                          wControl->Width + ::GetSystemMetrics(SM_CXFRAME),
                          wControl->Height + ::GetSystemMetrics(SM_CYCAPTION) + ::GetSystemMetrics(SM_CYFRAME),
                          hDC, 0, 0, SRCCOPY );
                ::ReleaseDC( wControl->Handle, hDC );
            }
      }

If the TWinControl has Components as well, the above block of
code needs to be executed for that control as well. Then, if
it has components, it needs to be executed again and so on.
For this reason, the above block needs to be placed into a
recursive function call.

There's also another couple lines of code missing from the
above block that has to do with painting the controls in grey-
scale. As you find a TWinControl, you need to save a pointer
to it along with it's WindowProc method (so that you can restore it later) and then set it's WindowProc to a dummy
method that swallows all of the messages sent to it.

>Of course, the above is an incomplete solution [...]

You will need to add message handling for when the form
receives WM_PAINT and WM_NCPAINT. I don't know (exactly)
how we're doing it but this worked for me:

    private:
        MESSAGE void __fastcall WMPaint  ( TWMPaint &Message );
        MESSAGE void __fastcall WMNCPaint( TMessage &Message );
    public:
        BEGIN_MESSAGE_MAP
            VCL_MESSAGE_HANDLER( WM_PAINT,   TWMPaint, WMPaint   )
            VCL_MESSAGE_HANDLER( WM_NCPAINT, TMessage, WMNCPaint )
        END_MESSAGE_MAP( TForm )

//-------------------------------------------------------------
MESSAGE void __fastcall TForm1::WMNCPaint(TMessage &Message)
{
    if( Bmp )
      {
          TRect R = Rect( 0, 0, Width, ::GetSystemMetrics(SM_CYCAPTION) + ::GetSystemMetrics(SM_CYFRAME) );
          ::BitBlt( hWindowDC, R.Left, R.Top, R.Right, R.Bottom, Bmp->Canvas->Handle, R.Left, R.Top, SRCCOPY );
          R = Rect( 0, ::GetSystemMetrics(SM_CYCAPTION) + ::GetSystemMetrics(SM_CYFRAME), ::GetSystemMetrics(SM_CYFRAME), Height );
          ::BitBlt( hWindowDC, R.Left, R.Top, R.Right, R.Bottom, Bmp->Canvas->Handle, R.Left, R.Top, SRCCOPY );
          R = Rect( ::GetSystemMetrics(SM_CYFRAME), Height - ::GetSystemMetrics(SM_CYFRAME), Width, Height );
          ::BitBlt( hWindowDC, R.Left, R.Top, R.Right, R.Bottom, Bmp->Canvas->Handle, R.Left, R.Top, SRCCOPY );
          R = Rect( Width - ::GetSystemMetrics(SM_CYFRAME), ::GetSystemMetrics(SM_CYCAPTION) + ::GetSystemMetrics(SM_CYFRAME), Width, Height );
          ::BitBlt( hWindowDC, R.Left, R.Top, R.Right, R.Bottom, Bmp->Canvas->Handle, R.Left, R.Top, SRCCOPY );
      }
    else
      {
          inherited::Dispatch(&Message);
      }
}
//-------------------------------------------------------------
MESSAGE void __fastcall TForm1::WMPaint(TWMPaint &Message)
{
    if( Bmp )
      {
          PAINTSTRUCT ps = { 0 };
          ::BeginPaint( Handle, &ps );
          ::ValidateRect( Handle, &ps.rcPaint );
          TRect R = ps.rcPaint;
          R.Left   += ::GetSystemMetrics(SM_CYFRAME);
          R.Top    += ::GetSystemMetrics(SM_CYCAPTION) + ::GetSystemMetrics(SM_CYFRAME);
          R.Right  += ::GetSystemMetrics(SM_CYFRAME);
          R.Bottom += ::GetSystemMetrics(SM_CYCAPTION) + ::GetSystemMetrics(SM_CYFRAME);
          ::BitBlt( hWindowDC, R.Left, R.Top, R.Right, R.Bottom, Bmp->Canvas->Handle, R.Left, R.Top, SRCCOPY );
          ::EndPaint( Handle, &ps );
      }
    else
      {
          inherited::Dispatch(&Message);
      }
}
//-------------------------------------------------------------

Then, for dialogs, add an OnShow event and for TForm's that
are modal, add an OnActivate event to get the gray-scaled
image painted:

//-------------------------------------------------------------
void __fastcall TForm1::OpenDialog1Show(TObject *Sender)
{
    SendMessage( Handle, WM_NCPAINT, 0, 0 );
    TRect R = ClientRect;
    ::InvalidateRect( Handle, &R, FALSE );
}
//-------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    CaptureFormImage();
    bool Executed = OpenDialog1->Execute();
    ReleaseFormImage();
    if( Executed )
      {
          //
      }
}
//-------------------------------------------------------------
void __fastcall TForm2::FormActivate(TObject *Sender)
{
    SendMessage( Application->MainForm->Handle, WM_NCPAINT, 0, 0 );
    TRect R = Application->MainForm->ClientRect;
    ::InvalidateRect( Application->MainForm->Handle, &R, FALSE );
}
//-------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
    CaptureFormImage();
    Form2->ShowModal();
    ReleaseFormImage();
}
//-------------------------------------------------------------


~ JD
Technical Details
Message-ID: <442cdc46$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.volia.net!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>

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.152.211.242
References:  <442b1df3$1@newsgroups.borland.com> <442bbd3f$1@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <442cdc46$1@newsgroups.borland.com>
Date: 30 Mar 2006 23:37:42 -0700
X-Trace: newsgroups.borland.com 1143790662 207.105.83.66 (30 Mar 2006 23:37:42 -0700)
Lines: 142
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail