/*----------------------------------------------------------------------
Copyright (C)2001 MJSoft. All Rights Reserved.
This source may be used freely as long as it is not sold for
profit and this copyright information is not altered or removed.
Visit the web-site at www.mjsoft.co.uk
e-mail comments to info@mjsoft.co.uk
File: SortListCtrl.cpp
Purpose: Provides a sortable list control, it will sort text, numbers
and dates, ascending or descending, and will even draw the
arrows just like windows explorer!
----------------------------------------------------------------------*/
#include "stdafx.h"
#include "..\global.h"
#include "SortListCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//#defines
#define FIRST_COLUMN 0
#define MIN_COLUMN_WIDTH 10
#define MAX_DROP_DOWN_ITEM_COUNT 10
CSortListCtrl::CSortListCtrl()
: m_iNumColumns( 0 )
, m_iSortColumn( -1 )
, m_bSortAscending( TRUE )
, m_nLastSelItem ( -1 )
, m_nCurSelItem ( -1 )
, m_nCurSelSubItem ( -1 )
, m_Callback_ListCtrl_AddListString ( NULL )
, m_pCombo ( NULL )
, m_pEdit ( NULL )
, m_wHitMask ( LVHT_ONITEM )
, m_nImageNum ( 0 )
, m_bSaveTypeMask ( FALSE )
, m_dwInitTypeMask ( LVS_REPORT )
, m_nNotSortTailItem ( -1 )
, m_Proc_SortListCtrl_FreeItemMemory ( NULL )
{
}
CSortListCtrl::~CSortListCtrl()
{
m_UIntAry_ColumnType.RemoveAll();
m_StrAry_CommonText.RemoveAll();
DeleteImageList ();
}
BEGIN_MESSAGE_MAP(CSortListCtrl, CListCtrl)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
//{{AFX_MSG_MAP(CSortListCtrl)
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomdrawList)
ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnClick)
ON_WM_DESTROY()
ON_NOTIFY_REFLECT(NM_CLICK, OnClick)
ON_WM_HSCROLL()
ON_WM_VSCROLL()
ON_WM_KEYDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSortListCtrl message handlers
// the heading text is in the format column 1 text,column 1 width;column 2 text,column 3 width;etc.
BOOL CSortListCtrl::SetHeadings( const CString& strHeadings )
{
int iStart = 0;
SetRedraw(FALSE);
for( ;; )
{
const int iComma = strHeadings.Find( _T(','), iStart );
if( iComma == -1 )
break;
const CString strHeading = strHeadings.Mid( iStart, iComma - iStart );
iStart = iComma + 1;
int iSemiColon = strHeadings.Find( _T(';'), iStart );
if( iSemiColon == -1 )
iSemiColon = strHeadings.GetLength();
const int iWidth = atoi( GetMultiByteChar(strHeadings.Mid( iStart, iSemiColon - iStart )) );
iStart = iSemiColon + 1;
if( InsertColumn( m_iNumColumns, strHeading, LVCFMT_LEFT, iWidth ) == -1 )
{
SetRedraw(TRUE);
return FALSE;
}
m_UIntAry_ColumnType.Add ( E_COLUMN_TYPE_NORMAL );
m_iNumColumns ++;
}
SetRedraw(TRUE);
return TRUE;
}
void CSortListCtrl::FreeItemMemory( const int iItem, BOOL bCallExteriorFreeFunc/*=TRUE*/ )
{
if ( bCallExteriorFreeFunc && m_Proc_SortListCtrl_FreeItemMemory )
m_Proc_SortListCtrl_FreeItemMemory ( this, iItem );
ItemData* pid = reinterpret_cast<ItemData*>( CListCtrl::GetItemData( iItem ) );
if ( !pid ) return;
DELETE_HEAP ( &pid->pAppItemData );
DELETE_HEAP ( &pid->lpToolTipText );
CWnd *pWnd = (CWnd*)pid->pShowRecordWnd;
if ( pWnd && ::IsWindow ( pWnd->m_hWnd ) )
pWnd->DestroyWindow();
DELETE_HEAP ( &pWnd );
pid->pShowRecordWnd = NULL;
if ( pid->pcspUserText )
{
delete pid->pcspUserText;
pid->pcspUserText = NULL;
}
LPCTSTR* arrpsz = pid->arrpsz;
if ( arrpsz )
{
for( int i = 0; i < m_iNumColumns; i++ )
{
if ( arrpsz[ i ] ) delete[] arrpsz[ i ];
}
delete[] arrpsz;
}
delete pid;
VERIFY( CListCtrl::SetItemData( iItem, NULL ) );
}
BOOL CSortListCtrl::DeleteItem( int iItem, BOOL bCallExteriorFreeFunc/*=TRUE*/ )
{
if ( iItem < 0 || iItem >= GetItemCount() )
return FALSE;
// 是禁止编辑的项
if ( !CanEdit ( iItem ) ) return FALSE;
FreeItemMemory( iItem, bCallExteriorFreeFunc );
// Call the base class method
BOOL bRet = CListCtrl::DeleteItem( iItem );
if ( GetItemCount() < 1 ) ClearShowRecordView ();
SyncSRWItem ( iItem );
return bRet;
}
BOOL CSortListCtrl::DeleteAllItems()
{
for( int iItem = 0; iItem < GetItemCount(); iItem ++ )
FreeItemMemory( iItem );
ClearShowRecordView ();
return CListCtrl::DeleteAllItems();
}
BOOL IsNumber( LPCTSTR pszText )
{
ASSERT_VALID_STRING( pszText );
int nLen = lstrlen( pszText );
for( int i = 0; i < nLen; i++ )
if( !_istdigit( pszText[ i ] ) && pszText[ i ]!= '.' )
return FALSE;
return TRUE;
}
int NumberCompare( LPCTSTR pszNumber1, LPCTSTR pszNumber2 )
{
ASSERT_VALID_STRING( pszNumber1 );
ASSERT_VALID_STRING( pszNumber2 );
const double iNumber1 = atof( GetMultiByteChar(pszNumber1) );
const double iNumber2 = atof( GetMultiByteChar(pszNumber2) );
if( iNumber1 < iNumber2 )
return -1;
if( iNumber1 > iNumber2 )
return 1;
return 0;
}
BOOL IsDate( LPCTSTR pszText )
{
ASSERT_VALID_STRING( pszText );
// format should be 99/99/9999.
if( lstrlen( pszText ) != 10 )
return FALSE;
return _istdigit( pszText[ 0 ] )
&& _istdigit( pszText[ 1 ] )
&& pszText[ 2 ] == _T('/')
&& _istdigit( pszText[ 3 ] )
&& _istdigit( pszText[ 4 ] )
&& pszText[ 5 ] == _T('/')
&& _istdigit( pszText[ 6 ] )
&& _istdigit( pszText[ 7 ] )
&& _istdigit( pszText[ 8 ] )
&& _istdigit( pszText[ 9 ] );
}
int DateCompare( CTime cTime1, CTime cTime2 )
{
if( cTime1 < cTime2 )
return -1;
if( cTime1 > cTime2 )
return 1;
return 0;
}
int CALLBACK CSortListCtrl::CompareFunction( LPARAM lParam1, LPARAM lParam2, LPARAM lParamData )
{
CSortListCtrl* pListCtrl = reinterpret_cast<CSortListCtrl*>( lParamData );
ASSERT( pListCtrl->IsKindOf( RUNTIME_CLASS( CListCtrl ) ) );
ItemData* pid1 = reinterpret_cast<ItemData*>( lParam1 );
if ( !pid1 ) return 0;
ItemData* pid2 = reinterpret_cast<ItemData*>( lParam2 );
if ( !pid2 ) return 0;
ASSERT( pid1 );
ASSERT( pid2 );
if ( pListCtrl->m_nNotSortTailItem > 0 )
{
for ( int i=0; i<pListCtrl->m_nNotSortTailItem; i++ )
{
int nNotSortItem = (pListCtrl->GetItemCount()-1) - i;
if ( nNotSortItem >= 0 )
{
if ( pListCtrl->CListCtrl::GetItemData ( nNotSortItem ) == (DWORD)pid2 )
{
return 0;
}
}
}
}
LPCTSTR pszText1 = pid1->arrpsz[ pListCtrl->m_iSortColumn ];
LPCTSTR pszText2 = pid2->arrpsz[ pListCtrl->m_iSortColumn ];
ASSERT_VALID_STRING( pszText1 );
ASSERT_VALID_STRING( pszText2 );
// digit
if( IsNumber( pszText1 ) )
return pListCtrl->m_bSortAscending ? NumberCompare( pszText1, pszText2 ) : NumberCompare( pszText2, pszText1 );
else
{
CTime cTime1, cTime2;
// date or time
if ( ConvertStrToCTime ( (TCHAR*)pszText1, cTime1 ) != 0 &&
ConvertStrToCTime ( (TCHAR*)pszText2, cTime2 ) != 0 )
return pListCtrl->m_bSortAscending ? DateCompare( cTime1, cTime2 ) : DateCompare( cTime2, cTime1 );
// text.
else
return pListCtrl->m_bSortAscending ? lstrcmp( pszText1, pszText2 ) : lstrcmp( pszText2, pszText1 );
}
}
void CSortListCtrl::OnColumnClick( NMHDR* pNMHDR, LRESULT* pResult )
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
const int iColumn = pNMListView->iSubItem;
// if it's a second click on the same column then reverse the sort order,
// otherwise sort the new column in ascending order.
Sort( iColumn, iColumn == m_iSortColumn ? !m_bSortAscending : TRUE );
*pResult = 0;
}
void CSortListCtrl::Sort( int iColumn, BOOL bAscending )
{
m_iSortColumn = iColumn;
m_bSortAscending = bAscending;
// show the appropriate arrow in the header control.
m_c
没有合适的资源?快使用搜索试试~ 我知道了~
投掷飞镖记分工具(WinCE)
共61个文件
h:25个
cpp:23个
rc:2个
5星 · 超过95%的资源 需积分: 32 45 下载量 13 浏览量
2007-12-13
14:50:57
上传
评论
收藏 227KB RAR 举报
温馨提示
操作系统 : Windows Mobile 5.0<br>说明 : 中秋节和家人赏月,一起玩一个投掷飞镖的游戏,就是从超市花20块买回来一个飞镖靶子挂在墙上,大家轮流各投3镖,为了游戏的趣味性我们用纸和笔<br>记下每个人的单镖得分和总得分,最后评出冠亚军并给予奖励。纸、笔、眼睛再加上晚上暗淡的灯光,常常出现累加记分时出错的情况,严重影响选手的成绩。<br>于是我看看手中的Dopod手机,便想到做一个软件在手机上,只要将每个人每镖的得分纪录下来,累计总分、总分排名以及计算冠亚军完全由软件自动完成,这样<br>我们就可以全心全意地投入游戏当中去。<br>你可以任意修改复制本代码,但请保留这段文字不要修改。<br>希望我能为中国的软件行业尽一份薄力!<br><br>
资源推荐
资源详情
资源评论
收起资源包目录
DartScore.rar (61个子文件)
resourcesp.h 2KB
APlayerData.cpp 2KB
APlayerData.h 303B
DartScoreDlg.h 1KB
stdafx.h 2KB
SortListCtrl
SortListCtrl.h 9KB
SortHeaderCtrl.h 4KB
SortListCtrl.cpp 43KB
SortHeaderCtrl.cpp 10KB
InitSys.h 88B
DartScore.sln 5KB
DartScoreppc.rc 5KB
DartScore.vcproj 24KB
DartScoresp.rc 8KB
DartScore.h 3KB
DialogWM.cpp 3KB
InitSys.cpp 907B
DartScore.cpp 3KB
DartScore.suo 178KB
DlgGameParameter.h 968B
DlgGameParameter.cpp 5KB
DartScoreSetup
DartScoreSetup.vddproj 6KB
DartScore.vcproj.CHRYS-T60.chrys.user 7KB
DlgGameFileList.cpp 2KB
Resourceppc.h 541B
stdafx.cpp 205B
global.cpp 44B
img
MainUI.bmp 135KB
DartScoresp.aps 54KB
DartScoreppc.aps 38KB
DialogWM.h 908B
DartScoreDlg.cpp 10KB
global.h 5KB
DlgOnePlayerScore.cpp 2KB
res
DartScore.ico 3KB
DartScoresp.rc2 895B
DartScoreppc.rc2 650B
DlgOnePlayerScore.h 627B
DlgGameFileList.h 546B
DlgAGameScore.h 840B
PublicFunc
OSRelate.h 504B
HwDir.h 3KB
UIHandle.h 2KB
UIHandle.cpp 9KB
Arithmetic.h 207B
Log.h 2KB
RegisterTable.cpp 19KB
PublicFunc.cpp 737B
RegisterTable.h 2KB
PublicFunc.h 456B
String.h 2KB
DateTime.cpp 8KB
DirFile.cpp 9KB
HwDir.cpp 13KB
Log.cpp 6KB
DirFile.h 1KB
OSRelate.cpp 3KB
Arithmetic.cpp 1KB
String.cpp 14KB
DateTime.h 745B
DlgAGameScore.cpp 7KB
共 61 条
- 1
资源评论
- kuoriyuhui2012-07-20除了不是中文,其他都好
- bhtlbhtl1232013-09-11一般吧 数据库那里不好 总是装不好 就自动退出 下载下来也就是借鉴借鉴界面风格了
cppcjz414
- 粉丝: 4
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功