具体的函数实现,如果需要我再贴上来。
void CMCTTView::ListItem()//刷新列表
{
int i = 0
if(!m_pSet->IsOpen())
AfxMessageBox("数据源未打开")
m_Item.SetExtendedStyle(m_Item.GetExtendedStyle()|LVS_EX_FULLROWSELECT)
m_Item.DeleteAllItems()
m_Item.SetRedraw(FALSE)
if (!m_pSet->GetRecordCount() == 0)
{
m_pSet->MoveFirst()
}
while(!m_pSet->IsEOF())
{
m_Item.InsertItem(i,"")
m_Item.SetItemText(i,0,m_pSet->m_column1)
m_Item.SetItemText(i,1,m_pSet->m_column2)
m_Item.SetItemText(i,2,m_pSet->m_column3)
m_Item.SetItemText(i,3,m_pSet->m_column4)
i+=1
m_pSet->MoveNext()
}
m_Item.SetRedraw(TRUE)
}
void CMCTTView::OnItemDel() //在view类中删除条目
{
// TODO: Add your control notification handler code here
int listIndex //当前选中项的索引
//首先得到点击的位置
POSITION pos=m_Item.GetFirstSelectedItemPosition()//0 basedm_item是指代列表控件
if(pos==NULL)
return
//得索引,通过POSITION转化
listIndex=m_Item.GetNextSelectedItem(pos)+1//1 based,so 1 added
m_pSet->SetAbsolutePosition(listIndex)
if ( MessageBox( _T( "你确定要删除当前单词信息吗?" ),
_T( "删除确认?" ), MB_OKCANCEL | MB_ICONQUESTION ) == IDOK )
{
m_pSet->Delete()
MessageBox( _T( "该单词信息已经被成功删除!" ),
_T( "删除成功!" ), MB_OK | MB_ICONASTERISK )
OnNext()
}
m_pSet->Requery()
//if(!m_pSet->GetRecordCount() == 0)
ListItem()
}
void CMCTTView::OnNext()
{
m_pSet->MoveNext()
if ( m_pSet->IsEOF() )
m_pSet->MoveFirst()
}
int CMCTTDoc::AddToAcc()//在doc类中添加数据
{
m_mCTTSet.AddNew()
CString str1,str2,str3,str4
str1.Format("%s",m_Index)
str2.Format("%f",m_UseHs)
str3.Format("%f",m_UseHj)
switch (m_HJStyle)
{
case 0:
str4 = CString("类型1")
break
case 1:
str4 = CString("类型2")
break
case 2:
str4 = CString("类型3")
break
}
m_mCTTSet.m_column1 = str1 //Index
m_mCTTSet.m_column2 = str2//the use of hansi
m_mCTTSet.m_column3 = str3//the use of hanji
m_mCTTSet.m_column4 = str4//the style of hanjie
m_mCTTSet.Update()
m_mCTTSet.Requery()
MessageBeep(MB_OK)
CMainFrame* pframe = (CMainFrame*)AfxGetMainWnd()
CMCTTView* pInterfaceView = (CMCTTView*)pframe->GetActiveView()
pInterfaceView->ListItem()
return 0
}
只有自己写一个转换函数:void _TextFloatFormat(CDataExchange* pDX, int nIDC,
void* pData, double value, int nSizeGcvt)
{
ASSERT(pData != NULL)
pDX->PrepareEditCtrl(nIDC)
HWND hWndCtrl
pDX->m_pDlgWnd->GetDlgItem(nIDC, &hWndCtrl)
const int TEXT_BUFFER_SIZE = 400
TCHAR szBuffer[TEXT_BUFFER_SIZE]
if (pDX->m_bSaveAndValidate)
{
::GetWindowText(hWndCtrl, szBuffer, _countof(szBuffer))
double d
if (_sntscanf_s(szBuffer, _countof(szBuffer), _T("%lf"), &d) != 1)
{
AfxMessageBox(AFX_IDP_PARSE_REAL)
pDX->Fail() // throws exception
}
*((double*)pData) = d
}
else
{
ATL_CRT_ERRORCHECK_SPRINTF(_sntprintf_s(szBuffer, _countof(szBuffer), _countof(szBuffer) -1, _T("%.*f"), nSizeGcvt, value))
AfxSetWindowText(hWndCtrl, szBuffer)
}
}
void TestDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX)
//DDX_Text(pDX, IDC_EDIT1, theDouble) //不用标准的交换函数,用上面的函数
_TextFloatFormat(pDX, IDC_EDIT1, &theDouble, theDouble, 15)// 15是小数后位数
}
在资源视图里面右键你加的listcontrol控件,然后添加成员变量。。。假如叫m_listctrl,然后在oninitdialog()函数里m_listctrl.insertitem(0,_t("aaa"))m_listctrl.insertitem(1,_t("bbb"))还有要注意一点。。mfc字符串都用cstring这种类型,你可以把你以前的string转换成cstring,就能直接替换这些_t("xxx")了欢迎分享,转载请注明来源:内存溢出
评论列表(0条)