在 VC6 專案中快速擁有 XP 風格按鈕 (圓角、藍邊框、熱態變色、ToolTip),最捷徑是整合意大利開發者 Davide Calabro 的 **CButtonST + CWinXPButtonST** 類別庫 (4 個檔案)。本文記錄整合步驟,讓你 10 分鐘內完成升級。

XPDlg。BtnST.h, BtnST.cpp, WinXPButtonST.h, WinXPButtonST.cpp,加入專案 (FileView)。AboutDlg.h:#include "WinXPButtonST.h",成員變數 CWinXPButtonST m_OK;。CAboutDlg (非主對話框) 添加訊息:WM_CTLCOLOR, WM_INITDIALOG。OnInitDialog 初始化按鈕:
m_OK.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30); // 熱態亮度偏移
m_OK.SetBkColor(RGB(162, 189, 252)); // 背景色 (淺藍)
m_OK.SetRounded(TRUE); // 關鍵:啟用圓角矩形
m_OK.SetTooltipText(_T("關閉")); // 內建 ToolTip
OnCtlColor 統一對話框背景色 (讓圓角按鈕融入):
HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
COLORREF crBack = (nCtlColor == CTLCOLOR_DLG || nCtlColor == CTLCOLOR_STATIC) ?
RGB(160, 180, 220) : RGB(233, 233, 220);
pDC->SetBkColor(crBack);
pDC->SetTextColor(RGB(0,0,0));
static HBRUSH hBrush = CreateSolidBrush(crBack); // 靜態避免重複建立
return hBrush;
}
DoDataExchange 綁定:DDX_Control(pDX, IDOK, m_OK);。CAboutDlg:CAboutDlg dlg; dlg.DoModal();。作者 Davide Calabro (davide_calabro@yahoo.com, https://www.softechsoftware.it) 註明:
非商業用途免費;商業用途需支付 $5 授權費。
專案若用於商業產品發布,請務必聯繫作者購買正式授權,支持開源生態。
CButtonST 基礎功能:圖示/文字、扁平/立體、熱態圖示、多狀態顏色、對齊、不規則形狀、選單、聲音。CWinXPButtonST 進階:SetRounded (圓角)、SetTooltipText (內建 Tip)、OffsetColor (動態色彩)、完整 XP 視覺風格模擬。這套庫是 VC6 時代 MFC 開發者打造現代化 UI 的利器,代碼品質極高,值得深入研究其實現細節 (如 DrawItem、TrackMouseEvent、CRgn 圓角裁剪等)。