取畫刷(HBrush)的6種方法

來源:互聯網
上載者:User
 
 

HBRUSH hbr;

第一種: hbr= CreateSolidBrush(RGB(255,0,0));    //單色的畫刷

第二種: hbr= (HBRUSH)GetStockObject(BLACK_BRUSH);  //只能取特定顏色的畫刷,如BLACK_BRUSH,GRAY_BRUSH等刷

第三種: hbr= CreatePatternBrush(HBITMAP hbmp);    //得到位元影像畫刷

第四種: hbr = CreateHatchBrush(int fnStyle, COLORREF clrref)    //建立一種帶陰影的畫刷


第五種: hbr= CreateBrushIndirect(LOGBRUSH);     //通過LOGBRUSH結構體來取畫刷
   

typedef struct tagLOGBRUSH {
    UINT         lbStyle; //畫刷類型
    COLORREF lbColor; //顏色
        LONG         lbHatch; //陰影
} LOGBRUSH, *PLOGBRUSH;

第六種: hbr= HBRUSH CreateDIBPatternBrush(       //通過與裝置無關位元影像建立一個畫刷
        HGLOBAL hglbDIBPacked,      // handle to DIB
     UINT fuColorSpec        // color table data
      );

例如:

HBRUSH CAfdView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);

// TODO: Change any attributes of the DC here
if (pWnd->GetDlgCtrlID()==IDC_STATIC1)
{
    pDC->SetTextColor(RGB(200,0,0));
    pDC->SetBkColor(RGB(0,0,255));
  static HBRUSH hBrush = CreateSolidBrush(RGB(222,0,255));
  return hBrush;
}
        // TODO: Return a different brush if the default is not desired
else
  return hbr;
}

改變對話方塊背景色

HBRUSH CDqfDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

// TODO: Change any attributes of the DC here

// TODO: Return a different brush if the default is not desired
if(nCtlColor == CTLCOLOR_DLG)
   {
   CBrush *brush;
    brush = new CBrush(RGB(221,221,221));
   return (HBRUSH)(brush->m_hObject);
   }
return hbr;
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.