반응형
헤더 파일에
typedef struct SORTPARAM
{
int columnIdx;
bool sortDirect;
CListCtrl *pList;
}SORTPARAM;
구조체와
bool m_bSortDirect;
bool 변수 추가 후
List Control의 HDN_ITEMCLICK 핸들러 추가
void CDocumentCheckUpReportDlg::OnHdnItemclickList(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
*pResult = 0;
SORTPARAM sParam;
sParam.pList = (CListCtrl *)GetDlgItem(IDC_LIST);
sParam.columnIdx = phdr->iItem;
sParam.sortDirect = m_bSortDirect;
sParam.pList->SortItemsEx( CompareFunc, (LPARAM)&sParam );
m_bSortDirect = !m_bSortDirect;
return;
}
SortItemsEx 함수 호출 시 호출되는 CallBack 함수 CompareFunc 추가
int CALLBACK CDocumentCheckUpReportDlg::CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
CListCtrl *pListCtrl = ((SORTPARAM *)lParamSort)->pList;
int columnIdx = ((SORTPARAM *)lParamSort)->columnIdx;
bool sortDirect = ((SORTPARAM *)lParamSort)->sortDirect;
CString strItem1 = pListCtrl->GetItemText(static_cast<int>(lParam1), columnIdx);
CString strItem2 = pListCtrl->GetItemText(static_cast<int>(lParam2), columnIdx);
return sortDirect ? _tcscmp((TCHAR *)(LPCTSTR)strItem1, (TCHAR *)(LPCTSTR)strItem2) : -_tcscmp((TCHAR *)(LPCTSTR)strItem1, (TCHAR *)(LPCTSTR)strItem2);
}
반응형
'MFC > Reference' 카테고리의 다른 글
[MFC] 메시지 박스 윈도우 최상단에 출력 (0) | 2024.12.08 |
---|