リストビューのハンドリングに lbClass を使用する |
|
|
lbClass *MyDlg;
lbClass *MyList;
LRESULT CALLBACK About( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
int nRow;
switch( message ) {
case WM_INITDIALOG:
MyDlg = new lbClass( hDlg );
MyDlg->CenterWindow();
MyList = new lbClass( GetDlgItem( hDlg, IDC_LISTVIEW ) );
MyList->LV_AddTitle( "ファイル名", 200 );
MyList->LV_AddTitle( "サイズ", 80 );
MyList->LV_AddTitle( "更新日", 120 );
MyList->LV_AddTitle( "属性", 100 );
return TRUE;
case WM_COMMAND:
if( LOWORD(wParam) == IDCANCEL ) {
delete MyList;
delete MyDlg;
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
if( LOWORD(wParam) == IDOK ) {
MyList->LV_Reset( );
HANDLE hFile;
BOOL bFirst = true;
BOOL bRet;
WIN32_FIND_DATA wfd;
hFile = FindFirstFile( "*.*", &wfd );
bRet = true;
while( hFile != INVALID_HANDLE_VALUE && bRet == (BOOL)true ) {
nRow = MyList->LV_AddRow();
MyList->LV_SetColumn( nRow, 0, wfd.cFileName );
bRet = FindNextFile( hFile, &wfd );
}
if ( !bRet ) {
FindClose( hFile );
}
return TRUE;
}
break;
}
return FALSE;
}
| |
|
|
FileTimeToSystemTime 関数を用いて更新日をセットする |
|
|
MyList->LV_Reset( );
HANDLE hFile;
BOOL bFirst = true;
BOOL bRet;
WIN32_FIND_DATA wfd;
FILETIME ft;
SYSTEMTIME st;
char work[128];
hFile = FindFirstFile( "*.*", &wfd );
bRet = true;
while( hFile != INVALID_HANDLE_VALUE && bRet == (BOOL)true ) {
FileTimeToLocalFileTime( &(wfd.ftLastWriteTime), &ft );
FileTimeToSystemTime( &ft, &st );
wsprintf(
work,
"%02d-%02d-%02d %02d:%02d:%02d",
st.wYear,
st.wMonth,
st.wDay,
st.wHour,
st.wMinute,
st.wSecond
);
nRow = MyList->LV_AddRow();
MyList->LV_SetColumn( nRow, 0, wfd.cFileName );
MyList->LV_SetColumn( nRow, 2, work );
bRet = FindNextFile( hFile, &wfd );
}
if ( !bRet ) {
FindClose( hFile );
}
| |
|
|
|