.h中:
//标题栏修改
void DrawTitleBar(CDC *pDC);
LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
void ShowBitmap(CDC *pDC, int x, int y, int nW, int nH, CBitmap &m_bitmap);
在cpp中:
//标题栏改变
void CBluePhoneDlg::DrawTitleBar(CDC *pDC)
{
CDC memDC;
CBitmap bmp;
CRect rect, rtTitle;
CPoint point;
GetClientRect(rect);
//获取标题栏大小
rtTitle.left = GetSystemMetrics(SM_CXFRAME);
rtTitle.top = GetSystemMetrics(SM_CYFRAME);
rtTitle.right = rect.right - rect.left - GetSystemMetrics(SM_CXFRAME);
rtTitle.bottom = rtTitle.top + GetSystemMetrics(SM_CYSIZE);
point.x = rect.right + GetSystemMetrics(SM_CXFRAME);
point.y = 30;
memDC.CreateCompatibleDC(NULL);
bmp.CreateCompatibleBitmap(pDC,point.x,point.y);
CBitmap *pOldBit=memDC.SelectObject(&bmp);
//背景颜色
//memDC.FillSolidRect(0,0,point.x,point.y,RGB(125,0,125));
贴图
CBitmap pic;
pic.LoadBitmap(IDB_BITMAP1);
ShowBitmap(&memDC,0,0, rtTitle.right, 30, pic);
pDC->BitBlt(0,0,point.x,point.y,&memDC,0,0,SRCCOPY);
pOldBit->DeleteObject();
memDC.DeleteDC();
bmp.DeleteObject();
}
LRESULT CBluePhoneDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
//return CDialog::DefWindowProc(message, wParam, lParam);
LRESULT lrst=CDialog::DefWindowProc(message, wParam, lParam);
if (message==WM_MOVE||message==WM_PAINT||message==WM_NCPAINT||message==WM_NCACTIVATE ||message == WM_NOTIFY)
{
CDC* pWinDC = GetWindowDC();
if (pWinDC)
DrawTitleBar(pWinDC);
ReleaseDC(pWinDC);
}
return lrst;
}
void CBluePhoneDlg::ShowBitmap(CDC *pDC, int x, int y, int nW, int nH, CBitmap &m_bitmap)
{
CDC memDc, mdc;
memDc.CreateCompatibleDC(NULL);
mdc.CreateCompatibleDC(NULL);
CBitmap memBitmap;
memBitmap.CreateCompatibleBitmap(pDC,nW,nH);
CBitmap *OldBmp = memDc.SelectObject(&m_bitmap);
mdc.SelectObject(&m_bitmap);
memDc.BitBlt(x,y,nW,nH,&mdc,0,0,SRCCOPY);
BITMAP bm;
m_bitmap.GetBitmap( &bm );
//贴图
//pDC->BitBlt(x, y,
// x + bm.bmWidth,y + bm.bmHeight,
// &MemDc,
// 0, 0,
// SRCCOPY);
//拉伸
pDC->StretchBlt(x,y, nW, nH ,&memDc,0,0,
bm.bmWidth,bm.bmHeight,SRCCOPY);
memDc.SelectObject(OldBmp);
memDc.DeleteDC();
}