(1)一种在图片控件上写字的方法
void ShowText(CRect rect, CDialog * dlg, int id , CString text , int fontSize,COLORREF color)
//rect:写字的范围
//dlg:对应的DLG的指针
//id:对应的DLG上的图片控件的ID
//text:要写的文本
//fontSize:字体大小 color:颜色
{
CDC *pDC=dlg->GetDlgItem(id) ->GetDC();
_ASSERT(pDC);
pDC->SetTextColor(color);
pDC->SetBkMode(TRANSPARENT);
CFont font;
font.CreateFont(fontSize,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE, GB2312_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DRAFT_QUALITY,FF_SWISS,_T("黑体"));
CFont * pOldfont = pDC->SelectObject(&font);
pDC->DrawText(text,rect,DT_LEFT);
pDC->SelectObject(pOldfont);
font.DeleteObject();
dlg->GetDlgItem(id)->ReleaseDC(pDC);
}
============================================================================
(2:切换图片控件上的位图,可以用作做点击效果
HBITMAP m_hbmp1;
m_hbmp1 =LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BITMAP_GoBackUnselect)); ((CStatic *)GetDlgItem(IDC_STATIC_ButtonList_GoBack))->SetBitmap(m_hbmp1);
============================================================================
(3)从文件中加载相应的图片
CStatic * pPic = (CStatic *)(GetDlgItem(IDC_Pic));
HBITMAP m_hbmp = SHLoadDIBitmap((LPCTSTR)path);
pPic->SetBitmap(m_hbmp);
====================================================
(4)在图片控件上加载图标
HICON m_hicon;
m_hicon = LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_ID)); CDC * pDC= GetDlgItem(showLable)->GetDC();
pDC->DrawIcon(0,0,m_hicon);
ReleaseDC(pDC);
阅读(925) | 评论(0) | 转发(0) |