typedef BOOL (__stdcall *FunSetLayeredWindowAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
FunSetLayeredWindowAttributes funSetLayeredWindowAttributes;
funSetLayeredWindowAttributes = (FunSetLayeredWindowAttributes)GetProcAddress(GetModuleHandle("user32.dll"), "SetLayeredWindowAttributes");ModifyStyleEx(NULL, 0x80000/*WS_EX_LAYERED*/); //紿楀彛瑕佹湁WS_EX_LAYERED灞炴ф墠鑳界敤璁劇疆閫忔槑鐨勯偅涓狝PI
enum{IDT_SHOW = 100, IDT_EXIT = 101};
鍦∣nInitDialog鏂規(guī)硶閲岄潰娣誨姞涓涓畾鏃跺櫒
switch(nIDEvent)
{
case IDT_SHOW:
funSetLayeredWindowAttributes(this->m_hWnd, 0, m_current % 255, 2);
m_current += 5;
if(m_current >= 255)
KillTimer(IDT_SHOW);
break;
case IDT_EXIT:
m_current -= 5;
funSetLayeredWindowAttributes(this->m_hWnd, 0, m_current % 255, 2);
if(m_current <= 5)
{
CDialog::OnCancel();
KillTimer(IDT_EXIT);
}
break;
}
ON_WM_CTLCOLOR()
娣誨姞鍝嶅簲鍑芥暟
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
瀹炵幇鍝嶅簲鍑芥暟
if(IDS_STATIC == pWnd->GetDlgCtrlID())
{
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)::GetStockObject(NULL_BRUSH);
}
榪欓噷, 灝佽浜嗕竴涓熀綾? 鏂逛究浠ュ悗鐢?br />FadeIODlg.h
#pragma once
class CFadeIODlg : public CDialog
{
DECLARE_MESSAGE_MAP()
public:
CFadeIODlg(UINT uDLGID, CWnd* pParent = NULL);
virtual ~CFadeIODlg();
protected:
virtual void DoDataExchange(CDataExchange* pDX);
virtual void OnCancel();
virtual void OnOK();
afx_msg BOOL OnInitDialog();
afx_msg void OnTimer(UINT nIDEvent);
private:
enum{ TIME_BEGIN = 100, TIME_END = 101};
typedef BOOL (__stdcall *FUNSetLayeredWindowAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
FUNSetLayeredWindowAttributes m_funTransparent;
enum{
MAX_TRANSPARENT = 255, //鏈澶ч忔槑搴?/span>
NUM_BEGIN = 10, //寮濮嬭鏃跺櫒鏃墮棿闂撮殧
NUM_END = 10, //緇撴潫璁℃椂鍣ㄦ椂闂撮棿闅?/span>
NUM_CHANGE = 5, //鏀瑰彉閫忔槑搴?/span>
};
int m_currentTransparent; //褰撳墠紿楀彛閫忔槑搴?/span>
};
FadeIODlg.cpp
#include "stdafx.h"
#include "UI.h"
#include "FadeIODlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CFadeIODlg::CFadeIODlg(UINT uDLGID, CWnd* pParent /* = NULL */)
: CDialog(uDLGID, pParent)
{}
CFadeIODlg::~CFadeIODlg()
{}
void CFadeIODlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CFadeIODlg, CDialog)
ON_WM_TIMER()
END_MESSAGE_MAP()
BOOL CFadeIODlg::OnInitDialog()
{
CDialog::OnInitDialog();
ModifyStyleEx(0, 0x80000);
m_currentTransparent = 0;
m_funTransparent = (FUNSetLayeredWindowAttributes)GetProcAddress(GetModuleHandle("User32.dll"), "SetLayeredWindowAttributes");
if(m_funTransparent)
{
//m_funTransparent(this->GetSafeHwnd(), 0, 0, 2);
SetTimer(TIME_BEGIN, NUM_BEGIN, NULL);
}
return TRUE;
}
void CFadeIODlg::OnTimer(UINT nIDEvent)
{
switch(nIDEvent)
{
case TIME_BEGIN:
if(m_currentTransparent <= MAX_TRANSPARENT)
{
m_funTransparent(this->GetSafeHwnd(), 0, m_currentTransparent, 2);
m_currentTransparent += NUM_CHANGE;
}
else
KillTimer(TIME_BEGIN);
break;
case TIME_END:
if(m_currentTransparent >= 0)
{
if(m_currentTransparent > MAX_TRANSPARENT)
m_currentTransparent = MAX_TRANSPARENT;
m_funTransparent(this->GetSafeHwnd(), 0, m_currentTransparent, 2);
m_currentTransparent -= NUM_CHANGE;
}
else
{
KillTimer(TIME_END);
CDialog::OnCancel();
}
break;
}
}
void CFadeIODlg::OnOK()
{
}
void CFadeIODlg::OnCancel()
{
if(m_funTransparent)
{
KillTimer(TIME_BEGIN);
SetTimer(TIME_END, NUM_END, NULL);
}
else
CDialog::OnCancel();
}
ok, 瀹屾垚, 浠ュ悗鐩存帴緇ф壙榪欎釜瀵硅瘽妗? 紼嶅井淇敼涓涓? 鏁堟灉灝卞嚭鏉ヤ簡