如何把 CMyListView 取自 CMyListCtrl 。
解决方案 »
- 如何是鼠标在整个屏幕中有效
- 问个改变button控件上内容的问题,谢谢
- 诚挚的请问哪儿有介绍串口通信书籍的下栽地址?还有:怎么去控制串口以二进制,ASCII,16进制传输呢?回答就有分的哦。
- 怎样把 CString 型 转换成 long 型? (注意,不是 int 型,因为数是很大的)
- 一个很简单的问题,怎么用一个CRecordSet类打开多个表进行查询操作,不是同时
- 屏蔽 shift del的问题
- glew32mx.lib与glew32.lib区别是什么????
- 如何设置一个Button的Cursor?
- 一家软件公司的应聘题。我觉得不错!大家可以看看。
- qt做moxa的头文件问题
- 如何挨个地激活MDI程序的所有子窗口?????
- 字符串与数值的相互转换函数有哪些?OS是WIN2000。
得到此控件的窗口句柄(CWnd *),然后强制转换为(CMyListCtrl *);
GetListCtrl()就会得到指向CListCtrl的指针。
说具体点,行吗?
这是什么意思?
myctrl.Create(LVS_REPORT,&rect,this, IDC_MYID);
这进一步说明了CListView实际上在消息响应方面就是用的CListCtrl的消息处理。
CListCtrl& m_Listview = (CListCtrl&) GetListCtrl();不是可以了。
下面是一个对该CListCtrl的显示操作:
CDaoFieldInfo fieldInfo;
int nFields;
CDaoTableDef td(m_pDatabase);
try
{
td.Open(m_strTableName);
nFields=td.GetFieldCount();
for(int j=0;j<nFields;j++){
td.GetFieldInfo(j,fieldInfo);
int nWidth=m_Listview.GetStringWidth(fieldInfo.m_strName)+30;
m_Listview.InsertColumn(j,fieldInfo.m_strName,LVCFMT_LEFT,nWidth);
}
}
catch(CDaoException* e)
{
e->ReportError();
e->Delete();
return;
}
td.Close();
//读取表数据
int nItem=0;
m_pImageList = new CImageList();
m_pImageList->Create(IDB_IMAGELIST, 16, 1, RGB(0,0,0));
try
{
CString strSelect=(_T("Select * From["));
strSelect+=m_strTableName;
strSelect+=_T("]");
m_pRecordset->Open(dbOpenDynaset,strSelect);
while(!m_pRecordset->IsEOF()){
COleVariant var;
var=m_pRecordset->GetFieldValue(0);
m_Listview.InsertItem(nItem,CCrack::strVARIANT(var));
for(int i=0;i<nFields;i++){
m_Listview.SetImageList(m_pImageList, LVSIL_SMALL);
var=m_pRecordset->GetFieldValue(i);
m_Listview.SetItemText(nItem,i,CCrack::strVARIANT(var));
}
nItem++;
m_pRecordset->MoveNext();
}
我的PreCreateWindow是这样:
BOOL CJwglView::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= LVS_REPORT;
return CListView::PreCreateWindow(cs);
}
m_Listview.SetImageList(m_pImageList, LVSIL_SMALL);
for(int i=1;i<nFields;i++){ var=m_pRecordset->GetFieldValue(i);
m_Listview.SetItemText(nItem,i,CCrack::strVARIANT(var));
}
CListCtrl m_list=GetListCtrl();
Paul DiLascia
Download the code for this article: CQA0111.exe (201KB)
Q
I made a custom control derived from CWnd, and now I want to use it as a view. My first solution was to embed the control into the view and handle OnSize in the view to position the control over the client area. The problem is that mouse messages go to the control and cannot be overridden in the view. The keystroke messages go to the view and must be manually forwarded to the control.
I read about CCtrlView as a base class for common controls. I've even managed to write the view around it (I believe that you wrote about this in an issue of MSJ), but I could not get it to work with my CWnd-based control. Can this be done, and how?
A ......