标签:
1.方法1: 加载BITMAP显示,缺点是:图片固定大小,不会自动拉伸
//资源文件里导入一张BITMAP,如 IDC_BITMAP1 //设置Button的Bitmap 属性为 TRUE //.cpp CBitmap PpBitmap = new CBitmap(); //创建图片对象 pBitmap->LoadBitmapA(IDB_BITMAP1); //从资源中加载图片 HBITMAP hBitmap = (HBITMAP)pBitmap->Detach(); m_btn1.SetBitmap(hBitmap); //按钮显示图片
2.方法2 在DrawItem里自绘按钮
//将Button的 Owner Draw属性设置为TRUE //在父窗口重载 虚函数 ON_WM_DRAWITEM -> OnDrawItem void xxxDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) { // TODO: 在此添加消息处理程序代码和/或调用默认值 if (nIDCtl == IDC_BUTTON2) { //绘制按钮框架 UINT uStyle = DFCS_BUTTONPUSH; //是否按下去了 if (lpDrawItemStruct->itemState & ODS_SELECTED ) { uStyle |= DFCS_PUSHED; } CDC dc; dc.Attach(lpDrawItemStruct->hDC); dc.DrawFrameControl(&lpDrawItemStruct->rcItem, DFC_BUTTON, uStyle); //输出文字 dc.SelectObject(&m_font); dc.SetTextColor(RGB(0,0, 255)); CString strText; strText = _T("Sylar Test"); dc.TextOut(lpDrawItemStruct->rcItem.left + 40, lpDrawItemStruct->rcItem.top + 25, strText); //是否得到焦点 if (lpDrawItemStruct->itemState & ODS_FOCUS) { //画虚框 CRect rcFocus = lpDrawItemStruct->rcItem; rcFocus.DeflateRect(3, 3); dc.DrawFocusRect(&rcFocus); } return; } CDialogEx::OnDrawItem(nIDCtl, lpDrawItemStruct); } //字体设置 CFont m_font; m_font.CreatePointFont(100, _T("宋体"), NULL);
3.方法3 继承CButton类,自己实现.
标签:
原文地址:http://www.cnblogs.com/SylarLiang-VC/p/5507229.html