要實現對話框淡入淺出效果, 還是挺簡單的, 說白了, 就是在對話框初始化時候加個定時器, 在對話框銷毀前也加個定時器, 定時器的操作, 無非就是更新對話框界面的透明度, 要改變對話框的透明度, 用一個API就搞定了:SetLayeredWindowAttributes

恩, 思路就是這樣, 這里上關鍵代碼吧
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屬性才能用設置透明的那個API

enum{IDT_SHOW = 100, IDT_EXIT = 101};
在OnInitDialog方法里面添加一個定時器

SetTimer(IDT_SHOW, 50, NULL);

同樣, 在OnCancel方法里面添加一個定時器, 順便把IDT_SHOW定時器給KILL掉
KillTimer(IDT_SHOW);
SetTimer(IDT_EXIT, 
50, NULL);

OnTimer方法這樣寫:
switch(nIDEvent)
{
case IDT_SHOW:
    funSetLayeredWindowAttributes(
this->m_hWnd, 0, m_current % 2552);
    m_current 
+= 5;
        
    
if(m_current >= 255)
        KillTimer(IDT_SHOW);
    
break;
case IDT_EXIT:
    m_current 
-= 5;
    funSetLayeredWindowAttributes(
this->m_hWnd, 0, m_current % 2552);
    
if(m_current <= 5)
    {
        CDialog::OnCancel();
        KillTimer(IDT_EXIT);
    }
    
break;
}

很簡單吧, 一個淡入淺出效果就出來了

另:
static控件背景透明
添加WM_CTLCOLOR消息映射
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);
}


這里, 封裝了一個基類, 方便以后用
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,        //最大透明度
        NUM_BEGIN = 10,                //開始計時器時間間隔
        NUM_END = 10,                //結束計時器時間間隔
        NUM_CHANGE = 5,                //改變透明度
    };

    
int            m_currentTransparent;    //當前窗口透明度
};


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(
00x80000);
    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, 完成, 以后直接繼承這個對話框, 稍微修改一下, 效果就出來了