急!MFC CListCtrl控件怎么实现透明效果?急,在线等 CListCtrl控件总把后面图片盖住,有什么办法能实现透明效果或换一个其它控件也能实现透明效果并带能放置几百个图标?有时间的话给个示例代码更好,我这里能实现效果即结貼。谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 方法一;把背景图贴到ListCtrl背景上,这是可以实现的方法二;用DC画到界面上,至于滚动,自己加个scrollbar处理下 谢谢yfh1985sdq!我以前没怎么用过,能帮一个简单的示例代码吗?谢谢! http://www.codeproject.com/KB/combobox/TransListBox.aspx 主要在onDrawItem和ONErasebkgnd()中处理了.这是我曾经实现的部分代码,你看看思路了.void CFMListBoxCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData; if(!lpszText) return; CString strText = lpszText; CDC dc; dc.Attach(lpDrawItemStruct->hDC); int nDCIndex = dc.SaveDC(); CFont * pOldFont = dc.SelectObject(m_pListBoxAnno->FMCreateFont()); COLORREF crOldTextColor = dc.GetTextColor(); COLORREF crOldBkColor = dc.GetBkColor(); int nMode = dc.SetBkMode(TRANSPARENT); if ((lpDrawItemStruct->itemAction | ODA_SELECT) && (lpDrawItemStruct->itemState & ODS_SELECTED)) { dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT)); dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT)); dc.FillSolidRect(&lpDrawItemStruct->rcItem,::GetSysColor(COLOR_HIGHLIGHT)); } else { dc.SetTextColor(m_pListBoxAnno->GetTextColor()); if(!m_pListBoxAnno->IsTransparent()) dc.FillSolidRect(&lpDrawItemStruct->rcItem,crOldBkColor); else DrawBackground(&dc,CRect(lpDrawItemStruct->rcItem)); } // Draw the text. UINT nFormat = 0; if(m_pListBoxAnno->IsMultiline()) nFormat |= DT_WORDBREAK; else nFormat |= DT_SINGLELINE; int nAlignType =m_pListBoxAnno->GetAlignType(); switch(nAlignType) { case TEXT_ALIGN_LEFT: nFormat |= DT_LEFT; break; case TEXT_ALIGN_CENTER: nFormat |= DT_CENTER; break; case TEXT_ALIGN_RIGHT: nFormat |= DT_RIGHT; break; }// DrawBackground(&dc,CRect(lpDrawItemStruct->rcItem));// if(lpszText[0] != '\0') if(!strText.IsEmpty()) dc.DrawText( lpszText, strlen(lpszText), &lpDrawItemStruct->rcItem, nFormat); TRACE("x1 = %d,y1 = %d,x2 = %d ,y2 = %d \n",lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top,lpDrawItemStruct->rcItem.right,lpDrawItemStruct->rcItem.bottom); // original values. dc.SetTextColor(crOldTextColor); dc.SetBkColor(crOldBkColor); dc.SelectObject(pOldFont); dc.SetBkMode(nMode); dc.RestoreDC(nDCIndex); dc.Detach();}void CFMListBoxCtrl::DrawBackground(CDC * pDC,CRect rect){ ASSERT(pDC); if (pDC) { if (m_pListBoxAnno->IsTransparent()) { CWnd* pMainWnd = AfxGetMainWnd(); if (pMainWnd) { CDocMgr* pDocMgr = (CDocMgr*)pMainWnd->SendMessage(WM_GET_DOCMGR); if (pDocMgr) { PIsm* pBkImg = pDocMgr->GetActivePageBkImg(); if (pBkImg) { CRect rcPos; m_pListBoxAnno->GetAnnoPos(rcPos); rcPos.NormalizeRect(); CRect rcClient(rect); CPoint ptOffset(rcPos.left,rcPos.top); //GetParent()->ClientToScreen(&rcClient); int nRatio = (int)pMainWnd->SendMessage(WM_GET_ZOOM_RATIO); // Draw the background image in the Edit control ptOffset.y += rect.top; FMISM_DrawImage(pDC,pBkImg,ptOffset,GetSafeHwnd(),rcClient,nRatio); return ; } } } } }}BOOL CFMListBoxCtrl::OnEraseBkgnd(CDC* pDC) { // TODO: Add your message handler code here and/or call default if (pDC) { if (m_pListBoxAnno->IsTransparent()) { CWnd* pMainWnd = AfxGetMainWnd(); if (pMainWnd) { CDocMgr* pDocMgr = (CDocMgr*)pMainWnd->SendMessage(WM_GET_DOCMGR); if (pDocMgr) { PIsm* pBkImg = pDocMgr->GetActivePageBkImg(); if (pBkImg) { CRect rcPos; m_pListBoxAnno->GetAnnoPos(rcPos); rcPos.NormalizeRect(); CPoint ptOffset(rcPos.left,rcPos.top); CRect rcClient; GetClientRect(&rcClient); int nRatio = (int)pMainWnd->SendMessage(WM_GET_ZOOM_RATIO); // Draw the background image in the Edit control FMISM_DrawImage(pDC,pBkImg,ptOffset,GetSafeHwnd(),rcClient,nRatio); return TRUE; } } } } } return CListBox::OnEraseBkgnd(pDC);} 操作系统的USB端口通信如何控制? 等待多个线程时出了点小问题 使用MSXML和智能指针遇到的问题!请高手指教! 请教!!!日历控件CMonthCalCtrl使用的疑问!!! 如何将两个声音文件(说话的声音和背景音乐)合并成一个文件? VC中连接数据库问题 ~~~~~程序员在江湖上混~~关键是要跟对人~~~~~~~~` 我是VC++的初学者,能不能介绍本学习用的书啊?谢谢了!! microsoft form2 .0 tabstrip的使用方法(如果设置标签头文本) 关于端口的监听功能 如何将对话框上的按钮只保留最小化和关闭,让最大化按钮不显示 为什么datagrid不显示数据
把背景图贴到ListCtrl背景上,这是可以实现的
方法二;
用DC画到界面上,至于滚动,自己加个scrollbar处理下
void CFMListBoxCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData;
if(!lpszText)
return;
CString strText = lpszText;
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
int nDCIndex = dc.SaveDC();
CFont * pOldFont = dc.SelectObject(m_pListBoxAnno->FMCreateFont()); COLORREF crOldTextColor = dc.GetTextColor();
COLORREF crOldBkColor = dc.GetBkColor();
int nMode = dc.SetBkMode(TRANSPARENT);
if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
(lpDrawItemStruct->itemState & ODS_SELECTED))
{
dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
dc.FillSolidRect(&lpDrawItemStruct->rcItem,::GetSysColor(COLOR_HIGHLIGHT)); }
else
{
dc.SetTextColor(m_pListBoxAnno->GetTextColor());
if(!m_pListBoxAnno->IsTransparent())
dc.FillSolidRect(&lpDrawItemStruct->rcItem,crOldBkColor);
else
DrawBackground(&dc,CRect(lpDrawItemStruct->rcItem)); }
// Draw the text.
UINT nFormat = 0;
if(m_pListBoxAnno->IsMultiline())
nFormat |= DT_WORDBREAK;
else
nFormat |= DT_SINGLELINE; int nAlignType =m_pListBoxAnno->GetAlignType();
switch(nAlignType)
{
case TEXT_ALIGN_LEFT:
nFormat |= DT_LEFT;
break;
case TEXT_ALIGN_CENTER:
nFormat |= DT_CENTER;
break;
case TEXT_ALIGN_RIGHT:
nFormat |= DT_RIGHT;
break;
}
// DrawBackground(&dc,CRect(lpDrawItemStruct->rcItem));
// if(lpszText[0] != '\0')
if(!strText.IsEmpty())
dc.DrawText(
lpszText,
strlen(lpszText),
&lpDrawItemStruct->rcItem,
nFormat);
TRACE("x1 = %d,y1 = %d,x2 = %d ,y2 = %d \n",lpDrawItemStruct->rcItem.left,
lpDrawItemStruct->rcItem.top,lpDrawItemStruct->rcItem.right,lpDrawItemStruct->rcItem.bottom);
// original values.
dc.SetTextColor(crOldTextColor);
dc.SetBkColor(crOldBkColor);
dc.SelectObject(pOldFont);
dc.SetBkMode(nMode);
dc.RestoreDC(nDCIndex);
dc.Detach();
}void CFMListBoxCtrl::DrawBackground(CDC * pDC,CRect rect)
{
ASSERT(pDC);
if (pDC)
{
if (m_pListBoxAnno->IsTransparent())
{
CWnd* pMainWnd = AfxGetMainWnd();
if (pMainWnd)
{
CDocMgr* pDocMgr = (CDocMgr*)pMainWnd->SendMessage(WM_GET_DOCMGR);
if (pDocMgr)
{
PIsm* pBkImg = pDocMgr->GetActivePageBkImg();
if (pBkImg)
{
CRect rcPos;
m_pListBoxAnno->GetAnnoPos(rcPos);
rcPos.NormalizeRect();
CRect rcClient(rect);
CPoint ptOffset(rcPos.left,rcPos.top);
//GetParent()->ClientToScreen(&rcClient);
int nRatio = (int)pMainWnd->SendMessage(WM_GET_ZOOM_RATIO);
// Draw the background image in the Edit control
ptOffset.y += rect.top;
FMISM_DrawImage(pDC,pBkImg,ptOffset,GetSafeHwnd(),rcClient,nRatio);
return ;
}
}
}
}
}
}BOOL CFMListBoxCtrl::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default if (pDC)
{
if (m_pListBoxAnno->IsTransparent())
{
CWnd* pMainWnd = AfxGetMainWnd();
if (pMainWnd)
{
CDocMgr* pDocMgr = (CDocMgr*)pMainWnd->SendMessage(WM_GET_DOCMGR);
if (pDocMgr)
{
PIsm* pBkImg = pDocMgr->GetActivePageBkImg();
if (pBkImg)
{
CRect rcPos;
m_pListBoxAnno->GetAnnoPos(rcPos);
rcPos.NormalizeRect();
CPoint ptOffset(rcPos.left,rcPos.top);
CRect rcClient;
GetClientRect(&rcClient);
int nRatio = (int)pMainWnd->SendMessage(WM_GET_ZOOM_RATIO);
// Draw the background image in the Edit control
FMISM_DrawImage(pDC,pBkImg,ptOffset,GetSafeHwnd(),rcClient,nRatio);
return TRUE;
}
}
}
}
} return CListBox::OnEraseBkgnd(pDC);
}