添加菜单栏自绘按钮

  添加   ON_WM_NCPAINT  
  void   CMyDlg::OnNcPaint()    
  {  
  CDialog::OnNcPaint();//   for   painting   messages  
  CDC   *pDC=GetWindowDC();  
  //CPoint   pt;pt.x=2;pt.y=2;  
  //pDC->DrawIcon(pt,m_hIcon);  
  CRect   rc;GetWindowRect(&rc);  
  CPen   blackpen,graypen,whitepen;CPen   *oldpen;  
  whitepen.CreatePen(PS_SOLID,1,RGB(255,255,255));  
  graypen.CreatePen(PS_SOLID,1,RGB(180,180,180));  
  blackpen.CreatePen(PS_SOLID,1,RGB(100,100,100));  
  oldpen=pDC->SelectObject(&whitepen);  
  pDC->MoveTo(rc.Width()-30,16);  
  pDC->LineTo(rc.Width()-30,6);  
  pDC->LineTo(rc.Width()-22,6);  
  pDC->SelectObject(&graypen);  
  pDC->LineTo(rc.Width()-22,15);  
  pDC->LineTo(rc.Width()-30,15);  
  pDC->SelectObject(&blackpen);  
  pDC->MoveTo(rc.Width()-30,16);  
  pDC->LineTo(rc.Width()-22,16);  
  pDC->LineTo(rc.Width()-22,6);  
  CBrush   *pBrush=new   CBrush;pBrush->CreateSolidBrush(RGB(200,200,200));  
  pDC->FillRect(CRect(rc.Width()-29,7,rc.Width()-23,14),pBrush);  
  pDC->MoveTo(rc.Width()-28,12);  
  pDC->LineTo(rc.Width()-24,12);  
  pDC->SelectObject(oldpen);  
  pDC=new   CDC;  
  }  
  然后在自己处理ON_WM_NCLBUTTONDOWN事件

原文地址:https://www.cnblogs.com/buffer/p/1434689.html