+BOOL CDefView::_Sort()
+{
+ HWND hHeader;
+ HDITEM hColumn;
+
+ if ((m_ListView.GetWindowLongPtr(GWL_STYLE) & ~LVS_NOSORTHEADER) == 0)
+ return TRUE;
+
+ hHeader = (HWND)m_ListView.SendMessage(LVM_GETHEADER, 0, 0);
+ ZeroMemory(&hColumn, sizeof(hColumn));
+
+ /* If the sorting column changed, remove the sorting style from the old column */
+ if ( (m_sortInfo.nLastHeaderID != -1) &&
+ (m_sortInfo.nLastHeaderID != m_sortInfo.nHeaderID) )
+ {
+ hColumn.mask = HDI_FORMAT;
+ Header_GetItem(hHeader, m_sortInfo.nLastHeaderID, &hColumn);
+ hColumn.fmt &= ~(HDF_SORTUP | HDF_SORTDOWN);
+ Header_SetItem(hHeader, m_sortInfo.nLastHeaderID, &hColumn);
+ }
+
+ /* Set the sorting style to the new column */
+ hColumn.mask = HDI_FORMAT;
+ Header_GetItem(hHeader, m_sortInfo.nHeaderID, &hColumn);
+
+ hColumn.fmt &= (m_sortInfo.bIsAscending ? ~HDF_SORTDOWN : ~HDF_SORTUP );
+ hColumn.fmt |= (m_sortInfo.bIsAscending ? HDF_SORTUP : HDF_SORTDOWN);
+ Header_SetItem(hHeader, m_sortInfo.nHeaderID, &hColumn);
+
+ /* Sort the list, using the current values of nHeaderID and bIsAscending */
+ m_sortInfo.nLastHeaderID = m_sortInfo.nHeaderID;
+ return m_ListView.SortItems(ListViewCompareItems, this);
+}
+