自绘ListCtrl

loseway 2010-11-01 11:14:44
自绘了一个ListCtrl,但右键总弹出一个菜单,显示“这是什么?”,菜单不是我加的,哪位高手能告诉我这个菜单怎么出现的?如何屏蔽?
...全文
323 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
向立天 2010-11-26
  • 打赏
  • 举报
回复
您好
我是本版版主
此帖已多日无人关注
请您及时结帖
如您认为问题没有解决可按无满意结帖处理
另外本版设置了疑难问题汇总帖
并已在版面置顶
相关规定其帖子中有说明
您可以根据规定提交您帖子的链接
如您目前不想结帖只需回帖说明
我们会删除此结帖通知

见此回复三日内无回应
我们将强制结帖

相关规定详见界面界面版关于版主结帖工作的具体办法
码侬 2010-11-02
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 loseway 的回复:]
引用 6 楼 muzizongheng 的回复:
指定PropertySheet的m_psh.dwFlags |= PSH_NOCONTEXTHELP;

如:

// This code fragment shows how to change CPropertySheet's settings
// before it is shown. After the changes, CP……
[/Quote]

用错了,这是加上。

PropertySheet的 m_psh.dwFlags &= ~PSH_NOCONTEXTHELP;
loseway 2010-11-02
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 ilysony 的回复:]
在你的工程里搜索字符串 “这是什么”
[/Quote]

貌似是触发了系统帮助,我的工程没有这个字串。。
loseway 2010-11-02
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 muzizongheng 的回复:]
指定PropertySheet的m_psh.dwFlags |= PSH_NOCONTEXTHELP;

如:

// This code fragment shows how to change CPropertySheet's settings
// before it is shown. After the changes, CPropertySheet has the
//……
[/Quote]

试过了,还是不管用~~
Sou2012 2010-11-02
  • 打赏
  • 举报
回复
在你的工程里搜索字符串 “这是什么”
killer2008_520 2010-11-02
  • 打赏
  • 举报
回复
重载一下 Clistctrl 的 OnRButtonDown ,不做操作就可以了a
muzizongheng 2010-11-02
  • 打赏
  • 举报
回复
指定PropertySheet的m_psh.dwFlags |= PSH_NOCONTEXTHELP;

如:

// This code fragment shows how to change CPropertySheet's settings
// before it is shown. After the changes, CPropertySheet has the
// caption "Simple Properties", no "Apply" button, and the
// second page (CColorPage) initially on top.

CPropertySheet dlgPropertySheet(_T("Simple PropertySheet"));

CStylePage stylePage;
CColorPage colorPage;
CShapePage shapePage;
dlgPropertySheet.AddPage(&stylePage);
dlgPropertySheet.AddPage(&colorPage);
dlgPropertySheet.AddPage(&shapePage);

dlgPropertySheet.m_psh.dwFlags |= PSH_NOCONTEXTHELP;
dlgPropertySheet.DoModal();
loseway 2010-11-02
  • 打赏
  • 举报
回复

void CMyPropertySheet::OnNMCustomDraw(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLVCUSTOMDRAW pLVCD = reinterpret_cast<LPNMLVCUSTOMDRAW>(pNMHDR);


CRect rectRow, rectList;

m_wndList.GetWindowRect(&rectList);
ScreenToClient(&rectList);
m_wndList.GetItemRect(0, &rectRow, LVIR_BOUNDS);
int iItemHeight = rectRow.Height();
int iItemTop = rectRow.top ;


::SelectObject(pLVCD->nmcd.hdc, m_ftList);


switch (pLVCD->nmcd.dwDrawStage)
{


case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:


*pResult = CDRF_NOTIFYSUBITEMDRAW;
break;
case (CDDS_ITEMPREPAINT | CDDS_SUBITEM):
{
int iCol = pLVCD->iSubItem ;
int iRow = (int)pLVCD->nmcd.dwItemSpec;
CRect rectItem(pLVCD->nmcd.rc), rectIcon;

//计算每个子项的矩形

rectItem.top = iItemTop + iRow * iItemHeight;
rectItem.bottom = rectItem.top + iItemHeight;

rectItem.left +=3;
rectItem.right -=3;

if (iRow == 0)
rectItem.top +=3;
CDC *pDC = CDC::FromHandle(pLVCD->nmcd.hdc);

LOGFONT lf;
::ZeroMemory(&lf, sizeof(lf));
pDC->GetCurrentFont()->GetLogFont(&lf);


//获得第图标所在的矩形
m_wndList.GetSubItemRect(iRow,0, LVIR_ICON, rectIcon);

const COLORREF clrBlack = RGB(0,0,0);
const COLORREF clrWhite = RGB(255,255,255);

if ((pLVCD->nmcd.uItemState & (CDIS_FOCUS | CDIS_SELECTED)) == (CDIS_FOCUS | CDIS_SELECTED))
{


pDC->FillSolidRect(&rectItem, m_clrTextBkSele);
pDC->SetTextColor(clrWhite);
pDC->TextOut(rectItem.left + rectIcon.Width() + 8, (iRow == 0?(rectItem.top - 3):rectItem.top) + (iItemHeight - abs(lf.lfHeight))/2, m_wndList.GetItemText(iRow, iCol), (int)_tcslen(m_wndList.GetItemText(iRow, iCol)));

::DrawIconEx(*pDC,rectIcon.left, rectIcon.top + (iItemHeight - 16) / 2,m_imgList.ExtractIcon(iRow),16,16,NULL,NULL,DI_NORMAL);

pDC->SetTextColor(clrBlack);

DrawGradientLine(pDC,m_clrSeprator,CPoint(rectItem.left, rectItem.bottom-1), CPoint(rectItem.right, rectItem.bottom-1));


}

else

{

pDC->FillSolidRect(&rectItem, clrWhite);

pDC->TextOut(rectItem.left + rectIcon.Width() + 8, (iRow == 0?(rectItem.top - 3):rectItem.top) + (iItemHeight - abs(lf.lfHeight))/2, m_wndList.GetItemText(iRow, iCol), (int)_tcslen(m_wndList.GetItemText(iRow, iCol)));

::DrawIconEx(*pDC,rectIcon.left, rectIcon.top + (iItemHeight - 16) / 2, m_imgList.ExtractIcon(iRow),16,16,NULL,NULL,DI_NORMAL);

DrawGradientLine(pDC,m_clrSeprator,CPoint(rectItem.left, rectItem.bottom-1), CPoint(rectItem.right, rectItem.bottom-1));



}


*pResult = CDRF_SKIPDEFAULT;
break;
}


default:
*pResult = CDRF_SKIPDEFAULT;
break;
}



}


void CMyPropertySheet::DrawGradientLine(CDC* pDC, COLORREF clrLine, POINT ptStart, POINT ptEnd)
{
//画渐近线,从clrLine的颜色变化至白色

int clrBBase = clrLine>>16 & 0x000000FF;
int clrGBase = clrLine>>8 & 0x000000FF;
int clrRBase = clrLine & 0x000000FF;

int clrBCurr = 255;
int clrGCurr = 255;
int clrRCurr = 255;

double dRInc = (double)(255 - clrRBase) / (double)(abs(ptEnd.x - ptStart.x));
double dGInc = (double)(255 - clrGBase) / (double)(abs(ptEnd.x - ptStart.x));
double dBInc = (double)(255 - clrBBase) / (double)(abs(ptEnd.x - ptStart.x));

POINT ptCurr = ptStart;

for (;ptCurr.x < ptEnd.x;ptCurr.x ++)
{
pDC->SetPixel(ptCurr.x, ptCurr.y -1,RGB(clrRCurr,clrGCurr,clrBCurr));
pDC->SetPixel(ptCurr, RGB(clrRCurr,clrGCurr,clrBCurr));
clrRCurr = clrRBase + (int)((ptCurr.x - ptStart.x) * dRInc);
clrGCurr = clrGBase + (int)((ptCurr.x - ptStart.x) * dGInc);
clrBCurr = clrBBase + (int)((ptCurr.x - ptStart.x) * dBInc);
}




}

int CMyPropertySheet::AddIcon(HICON icon)
{
return m_imgList.Add(icon);
}

void CMyPropertySheet::SetCaptionColor(const COLORREF clrCaption)
{
m_clrCaption = clrCaption;
}

void CMyPropertySheet::SetSepratorColor(const COLORREF clrSeprator)
{
m_clrSeprator = clrSeprator;
}

void CMyPropertySheet::SetListFont(CFont * pFont)
{
m_ftList.Attach(pFont->GetSafeHandle());
}

void CMyPropertySheet::SetSelectedColor(const COLORREF clrSelected)
{
m_clrTextBkSele = clrSelected;
}
loseway 2010-11-02
  • 打赏
  • 举报
回复
代码出自http://www.vckbase.com/document/viewdoc/?id=1805


// MyPropertySheet.cpp : 实现文件
//

#include "stdafx.h"

#include "MyPropertySheet.h"


// CMyPropertySheet
static BOOL bMoved[4] = {FALSE,FALSE,FALSE,FALSE};

IMPLEMENT_DYNAMIC(CMyPropertySheet, CPropertySheet)

CMyPropertySheet::CMyPropertySheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(nIDCaption, pParentWnd, iSelectPage), m_nSelectedItem(0), m_clrTextBkSele(RGB(0,132,255)),m_clrSeprator(RGB(0,132,255)),
m_clrCaption(RGB(92,132,255))
{
m_szCaption = new TCHAR[128];


//默认16*16,32位色图标
m_imgList.Create(16,16,ILC_COLOR32, 0, 20);

m_ftList.CreatePointFont(90,_T("宋体"));

}

CMyPropertySheet::CMyPropertySheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage), m_nSelectedItem(0), m_clrTextBkSele(RGB(0,132,255)),m_clrSeprator(RGB(0,132,255)),
m_clrCaption(RGB(92,132,255))
{
m_szCaption = new TCHAR[128];

m_imgList.Create(16,16,ILC_COLOR32, 0, 20);
m_ftList.CreatePointFont(90,_T("宋体"));

}

CMyPropertySheet::~CMyPropertySheet()
{

delete [] m_szCaption;

}


BEGIN_MESSAGE_MAP(CMyPropertySheet, CPropertySheet)
ON_WM_PAINT()
ON_NOTIFY(NM_CLICK, 0xFFFF, OnNMClick)
ON_NOTIFY(NM_CUSTOMDRAW,0xFFFF, OnNMCustomDraw)

END_MESSAGE_MAP()


// CMyPropertySheet 消息处理程序

BOOL CMyPropertySheet::OnInitDialog()
{

BOOL bResult = CPropertySheet::OnInitDialog();

//计算属性页的矩形,扩大属性表并将属性页其移至右侧
CRect rect, rectPage, rectTab;
GetPage(0)->GetWindowRect(&rectPage);

GetWindowRect(&rect);
rect.right += 150;

int nWidth = rectPage.Width();
rectPage.right = rect.right - 20;
rectPage.left = rect.right - nWidth;
ScreenToClient(&rectPage);
m_rectPage = rectPage;
MoveWindow(&rect);
GetPage(0)->MoveWindow(&rectPage);

//隐藏属性页原来的TabControl
CTabCtrl *pTab = GetTabControl() ;
pTab->GetWindowRect(&rectTab);
ScreenToClient(&rectTab);
if(!pTab->ShowWindow(SW_HIDE))
return FALSE;




//创建列表控件并用一个CImageList对象与之关联
if(!m_wndList.Create(WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_NOCOLUMNHEADER , CRect(10 ,rectTab.top,150,rectPage.bottom ),this,0xFFFF))
return FALSE;
m_wndList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
m_wndList.SetImageList(&m_imgList, LVSIL_SMALL);

InitList();

//这一步是为了扩大行高度
CFont font;
font.CreatePointFont(240,_T("宋体"));
m_wndList.SetFont(&font);

CString strCaption;
GetPage(0)->GetWindowText(strCaption);
_tcscpy(m_szCaption, strCaption.GetBuffer(strCaption.GetLength()));

return bResult;
}

void CMyPropertySheet::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rectList,rectPage;
m_wndList.GetWindowRect(&rectList);
GetPage(0)->GetWindowRect(&rectPage);
ScreenToClient(&rectPage);
ScreenToClient(&rectList);

rectList.left = rectList.left -1;
rectList.right = rectList.right + 1;
rectList.top = rectList.top - 1;
rectList.bottom = rectList.bottom + 1;

rectPage.left -= 1;
rectPage.right += 1;
rectPage.top -= 1;
rectPage.bottom += 1;
CBrush brush(RGB(141,141,141));
dc.FrameRect(&rectList,&brush);
dc.FrameRect(&rectPage, &brush);


DrawCaption(&dc, m_clrCaption);




}

void CMyPropertySheet::DrawCaption(CDC * pDC, const COLORREF clrCaption)
{
CDC dcBuf;
dcBuf.CreateCompatibleDC(pDC);
CBitmap bmp;

CRect rectCap, rectList, rectPage,rectSheet;
m_wndList.GetWindowRect(&rectList);
ScreenToClient(&rectList);
GetPage(0)->GetWindowRect(&rectPage);
ScreenToClient(&rectPage);

rectCap = rectPage;
rectCap.top = rectList.top -1;
rectCap.left -= 1;
rectCap.right += 1;
rectCap.bottom =rectPage.top -1 ;


GetClientRect(&rectSheet);

rectCap.bottom +=1;



bmp.CreateCompatibleBitmap(pDC, rectCap.right , rectSheet.Height());


dcBuf.SelectObject(bmp);

//起始颜色
int clrBBase = clrCaption>>16 & 0x000000FF;
int clrGBase = clrCaption>>8 & 0x000000FF;
int clrRBase = clrCaption & 0x000000FF;

//过渡中颜色
int clrRCurr = clrRBase;
int clrGCurr = clrGBase;
int clrBCurr = clrBBase;

//色彩增量
const double nRClrInc = (double)(255 - clrRBase) / (double)rectCap.Width() ;
const double nGClrInc = (double)(255 - clrGBase) / (double)rectCap.Width() ;
const double nBClrInc = (double)(255 - clrBBase) / (double)rectCap.Width() ;



//画渐进色标题

CRect drawRect = rectCap;

for (int nLeft = rectCap.left, nRight = rectCap.left + 1 ; nLeft < rectCap.right; nLeft ++, nRight ++)
{

drawRect.left = nLeft;
drawRect.right = nRight;

dcBuf.FillSolidRect(&drawRect, RGB(clrRCurr,clrGCurr,clrBCurr));

clrRCurr = (int)((nLeft - rectCap.left) * nRClrInc + clrRBase);
clrGCurr = (int)((nLeft - rectCap.left) * nGClrInc + clrGBase);
clrBCurr = (int)((nLeft - rectCap.left) * nBClrInc + clrBBase);

}



dcBuf.SetBkMode(TRANSPARENT);
CFont font;




font.CreatePointFont(110,_T("宋体"),pDC);
dcBuf.SelectObject(&font);



dcBuf.SetTextColor(RGB(0,0,0));
dcBuf.TextOut(rectCap.left + 26, rectCap.top +5,m_szCaption, (int)_tcslen(m_szCaption));
dcBuf.SetTextColor(RGB(255,255,255));
dcBuf.TextOut(rectCap.left + 25, rectCap.top + 4, m_szCaption, (int)_tcslen(m_szCaption));

::DrawIconEx(dcBuf,rectCap.left + 4, rectCap.top + 3, m_imgList.ExtractIcon(m_nSelectedItem),16, 16, NULL,NULL, DI_NORMAL);






pDC->BitBlt(rectCap.left,rectCap.top,rectCap.Width()+rectCap.Width(),rectCap.Height(),&dcBuf,rectCap.left,rectCap.top,SRCCOPY);

}

void CMyPropertySheet::OnNMClick(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE lpItem = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
m_nSelectedItem = lpItem->iItem ;

if (lpItem->iItem >= 0 && lpItem->iItem < m_wndList.GetItemCount())
{
m_nSelectedItem = lpItem->iItem;
CString strCaption = m_wndList.GetItemText(lpItem->iItem,0);
_tcscpy(m_szCaption, strCaption);



SetActivePage(m_nSelectedItem);

Invalidate();


GetPage(m_nSelectedItem)->MoveWindow(&m_rectPage);

m_wndList.SetFocus();
}


}
void CMyPropertySheet::InitList(void)
{
LVITEM lvi;
::ZeroMemory(&lvi, sizeof(lvi));


CHeaderCtrl *pHeader = m_wndList.GetHeaderCtrl();


pHeader->ShowWindow(SW_HIDE);

CRect rectList;
m_wndList.GetWindowRect(&rectList);
ScreenToClient(&rectList);
//报表头不会显示,但是是必需的
m_wndList.InsertColumn(0,_T("设置"), LVCFMT_CENTER, rectList.Width(), 0);


CString strCaption;

CTabCtrl *pTab = GetTabControl();
TCITEM tci;
::ZeroMemory(&tci,sizeof(tci));
tci.mask = TCIF_TEXT;
tci.cchTextMax = 256;
TCHAR szBuf[256] = {0};
tci.pszText = szBuf;

for (int idxPge = 0; idxPge < GetPageCount(); idxPge ++)
{
if(pTab->GetItem(idxPge, &tci))

{
lvi.iItem = idxPge;
lvi.iSubItem = 0;
lvi.iImage = idxPge;
lvi.mask = LVIF_TEXT | LVIF_IMAGE;
lvi.pszText = tci.pszText ;
m_wndList.InsertItem(&lvi);
}
}




}

muzizongheng 2010-11-02
  • 打赏
  • 举报
回复
你把你的listctrl源码给我看看。
muzizongheng 2010-11-02
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 gao_zilai 的回复:]
引用 9 楼 loseway 的回复:
引用 6 楼 muzizongheng 的回复:
指定PropertySheet的m_psh.dwFlags |= PSH_NOCONTEXTHELP;

如:

// This code fragment shows how to change CPropertySheet's settings
// before it is shown. ……
[/Quote]

仔细看好了, 是NoContextHelp, 怎么会加。。。
误导人。
loseway 2010-11-02
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 gao_zilai 的回复:]
引用 9 楼 loseway 的回复:
引用 6 楼 muzizongheng 的回复:
指定PropertySheet的m_psh.dwFlags |= PSH_NOCONTEXTHELP;

如:

// This code fragment shows how to change CPropertySheet's settings
// before it is shown. ……
[/Quote]

还是出现~
Eleven 2010-11-01
  • 打赏
  • 举报
回复
不是吧,自己在代码中找找看
loseway 2010-11-01
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 o_otwjo_o 的回复:]
在重绘的CLISTCTRL类,看看OnRButtonDown这信息有没有弹出菜单的代码,有就注释掉就行了
[/Quote]

这部分代码也不在里边,是右键触发了“这是什么?”系统帮助。。我搞不懂是怎么触发的?我的代码是CMyPropertySheet继承于CPropertySheet,然后在CMyPropertySheet的OnInitDialog里边Create一个列表控件(CListCtrl),之后在列表框里右键就会出现个菜单“这是什么?”。。
lesgo 2010-11-01
  • 打赏
  • 举报
回复
在重绘的CLISTCTRL类,看看OnRButtonDown这信息有没有弹出菜单的代码,有就注释掉就行了
loseway 2010-11-01
  • 打赏
  • 举报
回复
不是我加的,这个可以确定
job82824 2010-11-01
  • 打赏
  • 举报
回复
应该是拷贝的代码--然后自己改了其中一部分吧?右键的弹出菜单显然是代码里添加的。自己可以去找找看

15,976

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧