LRESULT OnPaint( HWND hWnd ) //繪制窗口時處理函數(shù)
{
CWnd* pWnd = CWnd::FromHandle(hWnd);
CPaintDC dc(pWnd);
CString Text; //標題
CRect RC; //區(qū)域
CFont Font; //字體
CFont *pOldFont; //原字體
CBrush Brush; //畫筆
CBrush *pOldBrush; //原畫筆
CPoint PT(2,2);
u dc.SetBkMode( TRANSPARENT ); //設(shè)置透明
v Font.CreateFont( 12, 0, 0, 0, FW_HEAVY, 0, 0, 0, ANSI_CHARSET, \
OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, \
VARIABLE_PITCH | FF_SWISS, "MS Sans Serif" ); //創(chuàng)建字體
pOldFont = dc.SelectObject( &Font ); //將畫筆選入設(shè)備環(huán)境
if( m_State == bsNormal) //判斷按鈕狀態(tài)
{
if (m_Style==2)
{
CBitmap bmp;
bmp.LoadBitmap(IDB_BKBUTTON); //加載圖片資源
Brush.CreatePatternBrush(&bmp); //根據(jù)圖片資源創(chuàng)建畫筆
}
else
Brush.CreateSolidBrush( RGB( 200, 200, 200 ) ); //用顏色創(chuàng)建畫筆
dc.SetTextColor( RGB( 80, 80, 80) ); //設(shè)置文本顏色
}
else if( m_State == bsDown ) //判斷按鈕是否按下
{
Brush.CreateSolidBrush( RGB( 160, 160, 160 ) ); //用顏色創(chuàng)建畫筆
dc.SetTextColor( RGB( 50, 50, 250 ) ); //設(shè)置文本顏色
}
else if( m_State == bsHot ) //判斷按鈕是否熱點
{
Brush.CreateSolidBrush( RGB( 100, 100, 180 ) ); //用顏色創(chuàng)建畫筆
dc.SetTextColor( RGB( 250, 250, 0 ) ); //設(shè)置文本顏色
}
pOldBrush = dc.SelectObject( &Brush ); //將畫刷選入設(shè)備環(huán)境中
pWnd->GetClientRect( &RC ); //獲得客戶區(qū)域
dc.RoundRect( &RC, PT ); //繪制圓角矩形
HRGN hRgn = CreateRectRgn( RC.left, RC.top, RC.right, RC.bottom ); //創(chuàng)建一個矩形區(qū)域
pWnd->SetWindowRgn( hRgn, TRUE ); //設(shè)置窗口區(qū)域
DeleteObject( hRgn );
pWnd->GetWindowText(Text ); //獲得窗口顯示文本
dc.DrawText( Text, &RC, DT_CENTER | DT_VCENTER | DT_SINGLELINE ); //繪制文本
dc.SelectObject( pOldFont );
dc.SelectObject( pOldBrush );