??xml version="1.0" encoding="utf-8" standalone="yes"?>
止ListCtrl表头拖动QPrevent CListCtrl column resizingQ?br />/*The header control in the ListView control sends notification to the parent window (e.i. the ListView) before it begins resizing a column. We can override the OnNotify() function in the CListCtrl derived class to handle this notification. The code below prevents resizing of all columns. Note that the resize cursor still shows up. */
BOOL CMyListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
switch (((NMHDR*)lParam)->code)
{
case HDN_BEGINTRACKW:
case HDN_BEGINTRACKA:
*pResult = TRUE; // disable tracking
return TRUE; // Processed message
}
return CListCtrl::OnNotify(wParam, lParam, pResult);
}
/*
If you want to prevent resizing of only one column, you should check for the value in iItem field of the HD_NOTIFY structure. The code below stops only the first column from being resized. */
BOOL CMyListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
HD_NOTIFY *pHDN = (HD_NOTIFY*)lParam;
if((pHDN->hdr.code == HDN_BEGINTRACKW || pHDN->hdr.code == HDN_BEGINTRACKA)
&& pHDN->iItem == 0) // Prevent only first (col# 0) from resizing
{
*pResult = TRUE; // disable tracking
return TRUE; // Processed message
}
return CListCtrl::OnNotify(wParam, lParam, pResult);
}
CStringArray arrLines;
arrLines.Add(sTitleRow);
stdFile.SeekToBegin();
CString str;
while(stdFile.ReadString(str))
{
arrLines.Add(str);
}
stdFile.SeekToBegin();
int nCount = arrLines.GetSize();
for ( int i = 0; i < nCount; i++ )
{
CString sContent;
if (i > 0)
{
sContent.Format("%d,%s", i, arrLines[i]);
}
else
{
sContent = arrLines[i];
}
stdFile.WriteString (sContent);
stdFile.WriteString ("\n");
}
stdFile.Close();
return TRUE;
}
return FALSE;
}
生成一个带标题的文?/strong>
BOOL CBarView::ExportDataFile(CString sDataFile/*, CStringArray &arsWriteString*/)
{
CStdioFile stdFile;
if ( stdFile.Open(sDataFile, CFile::modeCreate | CFile::modeNoTruncate
| CFile::modeReadWrite|CFile::shareExclusive) )
{
CString sTitleRow = "序号,文g?份数,|";
stdFile.WriteString (sTitleRow);
stdFile.WriteString ("\n");
for (int i = 0; i < (int)m_data.data.size(); i++)
{
CString sLineData;
for (int j = 0; j < (int)m_data.data.at(i).size(); j++)
{
CString sData = m_data.data.at(i).at(j);
if (j != 0)
{
sData.Format(", %s", sData);
}
else
{
sData.Format("%s", sData);
}
sLineData += sData;
}
CString sLine;
sLine.Format("%d, %s", (i+1), sLineData);
stdFile.WriteString (sLine);
stdFile.WriteString ("\n");
}
stdFile.Close();
return TRUE;
}
LOG("创徏文g %s p|", sDataFile);
return FALSE;
}
在网上查扄ListCtrlҎ
以下未经说明Q?span style="line-height: 1.3em">listctrl
-------------------------------------------------------------------------------
1. CListCtrl
LVS_ICON:
LVS_REPORT:
直观的理解:windows
2.
LONG lStyle;
lStyle = GetWindowLong(m_list.m_hWnd, GWL_STYLE);//
lStyle &= ~LVS_TYPEMASK; //
SetWindowLong(m_list.m_hWnd, GWL_STYLE, lStyle);//
DWORD dwStyle = m_list.GetExtendedStyle();
dwStyle |= LVS_EX_FULLROWSELECT;//
m_list.SetExtendedStyle(dwStyle); //
注:listview
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceshellui5/html/wce50lrflistviewstyles.asp
--------------------------------------------------------------------------------
3.
m_list.InsertColumn( 0, "ID", LVCFMT_LEFT, 40 );//
//新插入的在上?br />int nRow = m_list.InsertItem(0, "11");//
//新插入的数据在下?/span>
int nIndex = m_list.GetItemCount();
LV_ITEM lvItem;
lvItem.mask = LVIF_TEXT ;
lvItem.iItem = nIndex; //行数
lvItem.iSubItem = 0;
lvItem.pszText = (char*)(LPCTSTR)strCount; //W一?br />//在最后一行插入记录?
m_list.InsertItem(&lvItem);
//插入其它?br />m_list.SetItemText(nIndex,1,strLat);
--------------------------------------------------------------------------------
4.
选中style
--------------------------------------------------------------------------------
5.
int nIndex = 0;
//
m_list.SetItemState(nIndex, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
//
m_list.SetItemState(nIndex, 0, LVIS_SELECTED|LVIS_FOCUSED);
--------------------------------------------------------------------------------
6.
CString str;
for(int i=0; i<m_list.GetItemCount(); i++)
{
if( m_list.GetItemState(i, LVIS_SELECTED) == LVIS_SELECTED || m_list.GetCheck(i))
{
str.Format(_T("
AfxMessageBox(str);
}
}
--------------------------------------------------------------------------------
7.
Ҏ一Q?
CString str;
for(int i=0; i<m_list.GetItemCount(); i++)
{
if( m_list.GetItemState(i, LVIS_SELECTED) == LVIS_SELECTED )
{
str.Format(_T("
AfxMessageBox(str);
}
}
Ҏ二:
POSITION pos = m_list.GetFirstSelectedItemPosition();
if (pos == NULL)
TRACE0("No items were selected!\n");
Else
{
while (pos)
{
int nItem = m_list.GetNextSelectedItem(pos);
TRACE1("Item %d was selected!\n", nItem);
// you could do your own processing on nItem here
}
}
--------------------------------------------------------------------------------
8.
LVITEM lvi;
lvi.iItem = nItemIndex;
lvi.iSubItem = 0;
lvi.mask = LVIF_TEXT;
lvi.pszText = szBuf;
lvi.cchTextMax = 1024;
m_list.GetItem(&lvi);