分享
 
 
 

CFaderWnd.cpp

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

/*----------------------------------------------------------------------------*/

/* 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.

/*

/*----------------------------------------------------------------------------*/

///////////////////////////////////////////////////////////////////////////////

//

// An MFC class to fade out any window, requiring only one extra line of

// code, typically:

// new CFaderWnd(this);

//

// It uses the 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 deleting itself (tidies up and closes the door behind itself).

//

///////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#include "FaderWnd.h"

#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static 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)

{

ASSERT(pWndToFade);

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, nElapse, NULL);

}

}

CFaderWnd::~CFaderWnd()

{

}

BEGIN_MESSAGE_MAP(CFaderWnd, CWnd)

//{{AFX_MSG_MAP(CFaderWnd)

ON_WM_TIMER()

ON_WM_SETFOCUS()

//}}AFX_MSG_MAP

END_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 previous holder, if any.

if (pOldWnd)

pOldWnd->SetFocus();

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有