반응형
// ListsDlg.h
class CListsDlg : public CDialog
{
// Construction
public:
//--
CImageList m_LargeImage;
CImageList m_SmallImage;
//--
}
// ListsDlg.cpp
static CString strName[] = {_T("테스터1"), _T("테스터2"), _T("테스터3"), _T("테스터4"), _T("테스터5"), _T("테스터6"), _T("테스터7")};
static CString strMode[] = {_T("Icon"), _T("Small Icon"), _T("List"), _T("Report")};
BOOL CListsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
// 큰 아이콘 설정
m_LargeImage.Create(IDB_LARGE, 32, 1, RGB(0, 128, 128));
m_ctrlList.SetImageList(&m_LargeImage, LVSIL_NORMAL);
// 작은 아이콘 설정
m_SmallImage.Create(IDB_SMALL, 16, 1, RGB(0, 128, 128));
m_ctrlList.SetImageList(&m_SmallImage, LVSIL_SMALL);
// 컬럼 생성
CRect rect;
m_ctrlList.GetClientRect(&rect);
m_ctrlList.InsertColumn(0, _T("이름"), LVCFMT_LEFT, 100);
m_ctrlList.InsertColumn(1, _T("나이"), LVCFMT_RIGHT, 60);
m_ctrlList.InsertColumn(2, _T("성별"), LVCFMT_CENTER, 60);
m_ctrlList.InsertColumn(3, _T("전화번호"), LVCFMT_LEFT, rect.Width()-200);
// 이이템 추가
CString str;
for(int i=0; i<7; i++)
{
// 이름
m_ctrlList.InsertItem(i, strName[i], rand()%5);
// 나이
str.Format("%d", rand()%100);
m_ctrlList.SetItemText(i, 1, str);
// 성별
if(rand()%2 == 0)
str = _T("남자");
else
str = _T("여자");
m_ctrlList.SetItemText(i, 2, str);
// 전화
str.Format("%03d - %04d", rand()%1000, rand()%10000);
m_ctrlList.SetItemText(i, 3, str);
}
// 확장속성
m_ctrlList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
for(int k=0; k<4; k++)
m_ctrlCombo.AddString(strMode[k]);
m_ctrlCombo.SetCurSel(3);
return TRUE; // return TRUE unless you set the focus to a control
}
void CListsDlg::OnSelchangeCombo1()
{
// TODO: Add your control notification handler code here
switch(m_ctrlCombo.GetCurSel())
{
case 0: m_ctrlList.ModifyStyle(LVS_TYPEMASK, LVS_ICON); break;
case 1: m_ctrlList.ModifyStyle(LVS_TYPEMASK, LVS_SMALLICON); break;
case 2: m_ctrlList.ModifyStyle(LVS_TYPEMASK, LVS_LIST); break;
case 3: m_ctrlList.ModifyStyle(LVS_TYPEMASK, LVS_REPORT); break;
}
}
void CListsDlg::OnDelete()
{
// TODO: Add your control notification handler code here
POSITION pos;
while(pos = m_ctrlList.GetFirstSelectedItemPosition())
{
int nSelItem = m_ctrlList.GetNextSelectedItem(pos);
m_ctrlList.DeleteItem(nSelItem);
}
}
반응형
'C & C++ > MFC 컨트롤' 카테고리의 다른 글
[Ctrl] 컨트롤 색상변경 (0) | 2011.05.21 |
---|---|
[Edit] 숫자 문자 유효성 검사 (0) | 2011.05.21 |
[Button] Bitmap Button 02 (0) | 2011.05.21 |
[Button] Bitmap Button 01 (0) | 2011.05.21 |
[ToolTip] 정적툴팁 (0) | 2011.05.21 |
댓글