标题栏修改背景色或背景图

.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();


 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值