|
void CBitmapBtn::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
UINT uStyle = DFCS_BUTTONPUSH;
// This code only works with buttons.
ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON);
// Get the button's text.
CString strText=L"";
// TCHAR strbuf[100];
GetWindowText(strText);
// GetDlgItemText(GetDlgCtrlID(),strbuf,100);
// Draw the button text using the text color red.
BITMAP bm;
HDC hdc;
HBITMAP hbmp;
COLORREF crOldColor;
crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, mTextColor);
//2008--7--30 XQH 只是一个判断逻辑!
if (lpDrawItemStruct->itemState & ODS_DISABLED)
{
hbmp=thbmpdis[hindex];
//crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, crTextBk);
}
else if (lpDrawItemStruct->itemState & ODS_SELECTED)
{
if(lpDrawItemStruct->itemAction & ODA_SELECT)
{
hbmp=thbmpsel[hindex];
}
}
else if (lpDrawItemStruct->itemState & ODS_FOCUS)
{
hbmp=thbmpfoucs[hindex];
}
else
{
//2008--7--30 xqh_xg
// ::PostMessage(GetParent()->m_hWnd,WM_KILLFOCUS,(WPARAM)lpDrawItemStruct->hwndItem,0);
hbmp=thbmpup[hindex];
}
//===========================================
if((lpDrawItemStruct->itemAction & ODA_FOCUS) && (lpDrawItemStruct->itemState & ODS_FOCUS))
{
hbmp=thbmpfoucs[hindex];
}
if (hbmp==NULL) //2008--10--21 xqh 没有背景图就用UP状态下的位图
{
hbmp=thbmpup[hindex];
}
//===================================================================================
GetObject(hbmp,sizeof(BITMAP),&bm);
hdc=CreateCompatibleDC(lpDrawItemStruct->hDC); //2008--7--30 xqh_xg
SelectObject(hdc,hbmp);
BitBlt(lpDrawItemStruct->hDC,0,0,bm.bmWidth,bm.bmHeight,hdc,
0,0,SRCCOPY);
DeleteObject(hdc);
//2008--7--30 XQH 界面闪烁,怎么调节解决???
SetBkMode(lpDrawItemStruct->hDC,TRANSPARENT); //2008---7--30 XQH 这条语句起什么作用?
::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(),
&lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
}
//=====================================================================
上面是我的位图按钮类中对DRAWITEM的处理------根据按钮的状态,BITBLT不同的位图过去。
|
|