求助 cview类无法处理 WM_DRAWITEM 消息 求指教
// listView.cpp : implementation of the CMyListView class
//
#include "stdafx.h"
#include "list.h"
#include "listDoc.h"
#include "listView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyListView
IMPLEMENT_DYNCREATE(CMyListView, CView)
BEGIN_MESSAGE_MAP(CMyListView, CView)
//{{AFX_MSG_MAP(CMyListView)
ON_WM_CREATE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_WM_DRAWITEM()
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyListView construction/destruction
CMyListView::CMyListView()
{
// TODO: add construction code here
}
CMyListView::~CMyListView()
{
}
BOOL CMyListView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMyListView drawing
void CMyListView::OnDraw(CDC* pDC)
{
CListDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMyListView printing
BOOL CMyListView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMyListView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMyListView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMyListView diagnostics
#ifdef _DEBUG
void CMyListView::AssertValid() const
{
CView::AssertValid();
}
void CMyListView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CListDoc* CMyListView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CListDoc)));
return (CListDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyListView message handlers
int CMyListView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
m_plist = new CMylistCtrl;
::SendMessage(m_hWnd,WM_DRAWITEM,0,0);// TODO: Add your specialized creation code here
return 0;
}
void CMyListView::OnInitialUpdate()
{
CView::OnInitialUpdate();
CRect rect;
GetClientRect(&rect);
m_plist->Create(LVS_REPORT|LVS_OWNERDRAWFIXED,rect,this,2000);
m_plist->ModifyStyleEx(0,LVS_OWNERDRAWFIXED);
m_plist->ShowWindow(SW_SHOW);
// TODO: Add your specialized code here and/or call the base class
}
void CMyListView::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your message handler code here and/or call default
if(lpDrawItemStruct->CtlType == ODT_LISTVIEW)
m_plist->DrawItem(lpDrawItemStruct);
CView::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
[解决办法]
OnDrawItem是画窗口中的子控件的,它的入口参数LPDRAWITEMSTRUCT带入不同子控件的相关参数,得把子控件设置成“自画”类型,才会调用到OnDrawItem
[解决办法]
CMyListView 从何继承?