Cfaderwnd.cpp

xiaoxiao2021-03-06  69

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------- * // * cfaderWnd IMplementation * // * ------------ -------------------------------------------------- -------------- * //// File: faderwnd.cpp // Author: Phil J. Pearson // Created: 20 June 2000 14: 26 // Last Mod: 23 June 2000 19:06 /// * ------------------------------------------ --------------------------------- / * / * CopyRight (c) 2000 by real world software / * all Rights reserved. / */*------------------------------------------- --------------------------------- * /

//////////////// code, type, type, type, type); /// i i es UpdateLayeredWindow Function, Not Available On Win9x or NT.// It uses GetProcAddress instead of implicitly linking to the function so // that code using this class will load and run on any Win32 platform. If // the necessary function is not available then the fade will simply not // happen .// It works by making an exact copy of the source window and fading the copy // so it is usual to hide or destroy the source window immediately after // creating an instance of this class. For example, // new CFaderWnd ( THIS); // ShowWindow (SW_HIDE); // OR // new cfaderwnd (this); // destroyWindow (); // OR // new cfaderWnd (this); // enddialog (nresult); // Note That it's essential to construct the CFaderWnd FIRST.//// CFaderWnd must ALWAYS be contructed on the heap (with new CFaderWnd ...) .// It is NEVER necessary to call the destructor (delete ...) since CFaderWnd // takes care Of Del Etating itself (Tidies Up and Closes The Door BEHIND Itself) ./////

#include "stdafx.h" #include "faderwnd.h"

#ifdef _debug # define new debug_new # undef this_filestatic char this_file [] = __file __; # endif // how much we decrease the alpha each time # define alpha_step 5

/// cfaderwnd

CfaderWnd :: cfaderwnd (cwnd * pwndtofade, uint nfadetime / * = 2000 * /, byte byalpha / * = 255 * /): m_pwndtofade (pwndtofade) {askTTOFADE; Assert_Valid (PWNDTOFADE);

// Try to get the address of the updateLayeredWindow function. It may not be available. Hmodule huser32 = getModuleHandle (_T ("user32.dll"));

M_PUPDATELAYEREDWINDOW = (LPFNUPDATELAYEREDWINDOW) GetProcaddress (HUSER32, "UpdateLayeredWindow);

// if OS Doesn't Provide The Function We can't Fade, Just Commit Suicide. If (null == m_pupdateLayeredWindow) delete this; Else {CRECT RC; CPOINT PTSRC (0, 0); Size Size;

// Get the window rect of the source window. M_pwndtofade-> getWindowRect (RC);

.. // Make a new window to match // WS_EX_LAYERED is necessary for UpdateLayeredWindow to be enabled // WS_EX_TRANSPARENT allows mouse clicks through to the window "underneath", // (it's nothing to do with optical transparency) CreateEx (WS_EX_LAYERED. | WS_EX_TRANSPARENT | WS_EX_TOPMOST | WS_EX_TOOLWINDOW, "Static", "", WS_POPUP | WS_Visible, RC, AFXGETMAINWND (), 0);

// UpdateLayeredWindow Needs The size and origin of the source window. Size.cx = rc.width (); size.cy = rc.height (); ptsrc = rc.topleft (); // set up the blendfunction struct Used by UpdateLayeredWindow m_Blend.BlendOp = AC_SRC_OVER; // the only BlendOp defined in Windows 2000 m_Blend.BlendFlags = 0; // nothing else is special ... m_Blend.AlphaFormat = 0; // ... m_Blend.SourceConstantAlpha = byAlpha; // the initial alpha value // Display the new static window with the exact content and position of the source window. // When we return the caller can hide or destroy the source window and nothing will // appear to change. Subsequently (in OnTimer) we will reduce the alpha value to fade away // this copy window m_pUpdateLayeredWindow (GetSafeHwnd (), NULL, NULL, & size, :: GetDC (m_pWndToFade-> GetSafeHwnd ()), & ptSrc, 0, & m_Blend, ULW_ALPHA).;

// Calculate The Timer Interval Required To Complete The Fade In The Specified Time. Uint NELAPSE = NFADETIME / (Byalpha / Alpha_Step); SetTimer (1, NLAPSE, NULL);}}

CfaderWnd :: ~ cfaderwnd () {}

Begin_MESSAGE_MAP (CFADERWND, CWND) // {{AFX_MSG_MAP (CFADERWND) ON_WM_TIMER () ON_WM_SETFOCUS () //}} AFX_MSG_MAPEND_MESSAGE_MAP ()

/// cfaderwnd message handlers

void CFaderWnd :: OnTimer (UINT nIDEvent) {if (m_Blend.SourceConstantAlpha> = ALPHA_STEP) {// Reduce the alpha value (towards transparency) and update the window m_Blend.SourceConstantAlpha - = ALPHA_STEP;. m_pUpdateLayeredWindow (GetSafeHwnd (), NULL, NULL, NULL, NULL, NULL, NULL, & m_Blend, ULW_ALPHA);} else {// Reached minimum alpha Kill the timer and destroy our window // PostNcDestroy will delete this CFaderWnd instance KillTimer (nIDEvent);... DestroyWindow (); }} Void cfaderWnd :: OnsetFocus (CWND * PoldWnd) {// WHEN We get the input focus pass it back to the prepvious holder, if any. If (PoldWnd) PoldWnd-> setfocus ();

转载请注明原文地址:https://www.9cbs.com/read-87451.html

New Post(0)