類CList支持可按順序或按值訪問的非唯一對象的有序列表。CList 列表與雙鏈接列表行為相似。
例子:
一、添加:1、SINGERLISTDETAIL singerdetail;
for(;;)
{ MainDlg->cls_kodLogic->InsertBatchSingerItem( singerdetail ); }
2、void KodLogic::InsertBatchSingerItem(SINGERLISTDETAIL item)
{
cls_KodData->InsertBatchSingerItem( item );
}
3、void KodData::InsertBatchSingerItem(SINGERLISTDETAIL item)
{
m_RowBatchSingerList.AddTail( item );//AddTail 添加一個新元素或元素列表到此列表的標
//題后面。操作前此列表可能為空。
}
(聲明:CList<SINGERLISTDETAIL, SINGERLISTDETAIL&>m_RowBatchSingerList; (#include<afxtempl.h>))
二、此數據的提取:1、for( ; ; )
{ singerdetail = MainDlg->cls_kodLogic->GetBatchArtistItem(i); }
2、SINGERLISTDETAIL KodLogic::GetBatchArtistItem(int index)
{
POSITION pos;
CList<SINGERLISTDETAIL, SINGERLISTDETAIL&> *RowArtistList;
SINGERLISTDETAIL artistdetail;
RowArtistList = GetRowBatchSingerList();
pos = RowArtistList->FindIndex( index );// 使用nIndex值作為列表索引。它從
//頭開始順序掃描,停止於第幾個元素。
artistdetail = RowArtistList->GetAt(pos);
return artistdetail;
}
加 CList<SINGERLISTDETAIL, SINGERLISTDETAIL&>*KodLogic::GetRowBatchSingerList()
{
return cls_KodData->GetRowBatchSingerList();
}
3、CList<SINGERLISTDETAIL, SINGERLISTDETAIL&>* KodData::GetRowBatchSingerList()
{
return &m_RowBatchSingerList;
}
//2、 通過序號獲取歌星記錄
bool KodLogic::GetSingerItem(CString singerid, SINGERLISTDETAIL& outputsingerdetail)
{
CList<SINGERLISTDETAIL, SINGERLISTDETAIL&> *RowSingerList;
RowSingerList = GetRowSingerList();
int itemcnt = RowSingerList->GetCount();
POSITION pos = RowSingerList->GetHeadPosition();
SINGERLISTDETAIL singerdetail;
for( int i=0; i<itemcnt; i++ )
{
singerdetail = RowSingerList->GetAt(pos);
if( 0 == strcmp( singerdetail.Singerid, singerid ) )
{
outputsingerdetail = singerdetail;
return true;
}
RowSingerList->GetNext(pos);
}
return false;
}
三、清空此列表數據:1、MainDlg->cls_kodLogic->DeleteBatchArtistAllItem();
2、void KodLogic::DeleteBatchArtistAllItem(void)
{
cls_KodData->DeleteBatchAirtistAllItem();
}
3、void KodData::DeleteBatchAirtistAllItem(void)
{
m_RowBatchSingerList.RemoveAll();//RemoveAll從此列表中刪除所有元素並釋放
//相關的內存。如果列表已經是空的,則不會出錯。
}
最后的結構體typedef struct SINGERLISTDETAIL{
CString Singerid;
CString SingerInitials;
CString SingerNumber;
CString SingerName;
CString SingerSex;
CString SingerPlace;
bool HavePic;
CString ListFileIndex;
CString PicPath;
#ifdef ACE1100
CString SingerPlaceAndSex;
#endif
}SINGERLISTDETAIL;
完!
int = atoi( CString ) CSting.Format( “%d”, int )
修改窗口屬性
說明:
以下函數對於POPUP窗口有效,對於子窗口好像不行。
//最小化按鈕有效
::SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE) | WS_MINIMIZEBOX );
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);
//最小化按鈕無效
::SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE) &~WS_MINIMIZEBOX );
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);
//最大化按鈕有效
::SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE) | WS_MAXIMIZEBOX );
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);
//最大化按鈕無效
::SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE) &~WS_MAXIMIZEBOX );
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);
//關閉按鈕有效
::EnableMenuItem(::GetSystemMenu(m_hWnd,false),SC_CLOSE,MF_BYCOMMAND | MF_GRAYED);
//關閉按鈕無效
::EnableMenuItem(::GetSystemMenu(m_hWnd,false),SC_CLOSE,MF_BYCOMMAND | MF_ENABLED);
//工具欄窗口。在任務欄上沒有程序顯示,需要添加在OnInitDialog()里
::SetWindowLong(m_hWnd,GWL_EXSTYLE,GetWindowLong(m_hWnd,GWL_EXSTYLE)
&~WS_EX_APPWINDOW|WS_EX_TOOLWINDOW );
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE);
//添加標題欄
::SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE)
| WS_CAPTION );
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);
//取消標題欄
::SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE)
& ~WS_CAPTION );
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);
//取消標題欄,保留3d邊框,可調整窗口大小
::SetWindowLong(m_hWnd,GWL_STYLE, GetWindowLong(m_hWnd,GWL_STYLE)
& ~WS_CAPTION | WS_THICKFRAME );
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED); //一定要加這句設置才會立即生效
//取消標題欄和3d邊框,保留一個線條的細邊框,不能調整窗口大小
::SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE)
& ~WS_CAPTION & ~WS_THICKFRAME | WS_BORDER );
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);
//如果有WS_EX_DLGMODALFRAME還要取消WS_EX_DLGMODALFRAME
// ::SetWindowLong(m_hWnd,GWL_EXSTYLE,GetWindowLong(m_hWnd,GWL_EXSTYLE)
// & ~WS_EX_DLGMODALFRAME);
// ::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE);
//取消所有邊框
::SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE)
& ~WS_CAPTION & ~WS_THICKFRAME );
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);
// //如果有WS_EX_DLGMODALFRAME還要取消WS_EX_DLGMODALFRAME
// ::SetWindowLong(m_hWnd,GWL_EXSTYLE,GetWindowLong(m_hWnd,GWL_EXSTYLE)
// & ~WS_EX_DLGMODALFRAME);
// ::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE);