void CManageBookmarksDialog::GetBookmarkColumnInfo(const CBookmark &Bookmark, CManageBookmarksDialogPersistentSettings::ColumnType_t ColumnType, TCHAR *szColumn,size_t cchBuf) { switch(ColumnType) { case CManageBookmarksDialogPersistentSettings::COLUMN_TYPE_NAME: StringCchCopy(szColumn,cchBuf,Bookmark.GetName().c_str()); break; case CManageBookmarksDialogPersistentSettings::COLUMN_TYPE_LOCATION: StringCchCopy(szColumn,cchBuf,Bookmark.GetLocation().c_str()); break; case CManageBookmarksDialogPersistentSettings::COLUMN_TYPE_VISIT_DATE: { /* TODO: Friendly dates. */ FILETIME ftLastVisited = Bookmark.GetDateLastVisited(); CreateFileTimeString(&ftLastVisited,szColumn,static_cast<int>(cchBuf),FALSE); } break; case CManageBookmarksDialogPersistentSettings::COLUMN_TYPE_VISIT_COUNT: StringCchPrintf(szColumn,cchBuf,_T("%d"),Bookmark.GetVisitCount()); break; case CManageBookmarksDialogPersistentSettings::COLUMN_TYPE_ADDED: { /* TODO: Friendly dates. */ FILETIME ftCreated = Bookmark.GetDateCreated(); CreateFileTimeString(&ftCreated,szColumn,static_cast<int>(cchBuf),FALSE); } break; case CManageBookmarksDialogPersistentSettings::COLUMN_TYPE_LAST_MODIFIED: { /* TODO: Friendly dates. */ FILETIME ftModified = Bookmark.GetDateModified(); CreateFileTimeString(&ftModified,szColumn,static_cast<int>(cchBuf),FALSE); } break; default: assert(FALSE); break; } }
HRESULT CDropHandler::CopyTextToFile(IN TCHAR *pszDestDirectory, IN WCHAR *pszText,OUT TCHAR *pszFullFileNameOut) { SYSTEMTIME st; FILETIME ft; FILETIME lft; HRESULT hr = E_FAIL; TCHAR szTime[512]; GetLocalTime(&st); SystemTimeToFileTime(&st,&ft); LocalFileTimeToFileTime(&ft,&lft); CreateFileTimeString(&lft,szTime,SIZEOF_ARRAY(szTime),FALSE); for(int i = 0;i < lstrlen(szTime);i++) { if(szTime[i] == '/') { szTime[i] = '-'; } else if(szTime[i] == ':') { szTime[i] = '.'; } } TCHAR szFullFileName[MAX_PATH]; TCHAR szFileName[MAX_PATH]; /* TODO: Move text into string table. */ StringCchPrintf(szFileName,SIZEOF_ARRAY(szFileName), _T("Clipboard Text (%s).txt"),szTime); PathCombine(szFullFileName,pszDestDirectory, szFileName); HANDLE hFile = CreateFile(szFullFileName, GENERIC_WRITE,0,NULL,CREATE_NEW, FILE_ATTRIBUTE_NORMAL,NULL); if(hFile != INVALID_HANDLE_VALUE) { DWORD nBytesWritten; WriteFile(hFile,(LPCVOID)pszText, lstrlen(pszText) * sizeof(WCHAR), &nBytesWritten,NULL); CloseHandle(hFile); StringCchCopy(pszFullFileNameOut,MAX_PATH, szFullFileName); hr = S_OK; } return hr; }
INT_PTR CDestroyFilesDialog::OnInitDialog() { m_hDialogIcon = LoadIcon(GetModuleHandle(0),MAKEINTRESOURCE(IDI_MAIN_SMALL)); SetClassLongPtr(m_hDlg,GCLP_HICONSM,reinterpret_cast<LONG_PTR>(m_hDialogIcon)); HWND hListView = GetDlgItem(m_hDlg,IDC_DESTROYFILES_LISTVIEW); HIMAGELIST himlSmall; Shell_GetImageLists(NULL,&himlSmall); ListView_SetImageList(hListView,himlSmall,LVSIL_SMALL); SetWindowTheme(hListView,L"Explorer",NULL); ListView_SetExtendedListViewStyleEx(hListView, LVS_EX_DOUBLEBUFFER|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES, LVS_EX_DOUBLEBUFFER|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES); LVCOLUMN lvColumn; TCHAR szTemp[128]; LoadString(GetInstance(),IDS_DESTROY_FILES_COLUMN_FILE, szTemp,SIZEOF_ARRAY(szTemp)); lvColumn.mask = LVCF_TEXT; lvColumn.pszText = szTemp; ListView_InsertColumn(hListView,0,&lvColumn); LoadString(GetInstance(),IDS_DESTROY_FILES_COLUMN_TYPE, szTemp,SIZEOF_ARRAY(szTemp)); lvColumn.mask = LVCF_TEXT; lvColumn.pszText = szTemp; ListView_InsertColumn(hListView,1,&lvColumn); LoadString(GetInstance(),IDS_DESTROY_FILES_COLUMN_SIZE, szTemp,SIZEOF_ARRAY(szTemp)); lvColumn.mask = LVCF_TEXT; lvColumn.pszText = szTemp; ListView_InsertColumn(hListView,2,&lvColumn); LoadString(GetInstance(),IDS_DESTROY_FILES_COLUMN_DATE_MODIFIED, szTemp,SIZEOF_ARRAY(szTemp)); lvColumn.mask = LVCF_TEXT; lvColumn.pszText = szTemp; ListView_InsertColumn(hListView,3,&lvColumn); int iItem = 0; for each(auto strFullFilename in m_FullFilenameList) { TCHAR szFullFilename[MAX_PATH]; StringCchCopy(szFullFilename,SIZEOF_ARRAY(szFullFilename), strFullFilename.c_str()); /* TODO: Perform in background thread. */ SHFILEINFO shfi; SHGetFileInfo(szFullFilename,0,&shfi,sizeof(shfi),SHGFI_SYSICONINDEX| SHGFI_TYPENAME); LVITEM lvItem; lvItem.mask = LVIF_TEXT|LVIF_IMAGE; lvItem.iItem = iItem; lvItem.iSubItem = 0; lvItem.pszText = szFullFilename; lvItem.iImage = shfi.iIcon; ListView_InsertItem(hListView,&lvItem); ListView_SetItemText(hListView,iItem,1,shfi.szTypeName); WIN32_FILE_ATTRIBUTE_DATA wfad; GetFileAttributesEx(szFullFilename,GetFileExInfoStandard,&wfad); TCHAR szFileSize[32]; ULARGE_INTEGER lFileSize = {wfad.nFileSizeLow,wfad.nFileSizeHigh}; FormatSizeString(lFileSize,szFileSize,SIZEOF_ARRAY(szFileSize)); ListView_SetItemText(hListView,iItem,2,szFileSize); TCHAR szDateModified[32]; CreateFileTimeString(&wfad.ftLastWriteTime,szDateModified, SIZEOF_ARRAY(szDateModified),m_bShowFriendlyDates); ListView_SetItemText(hListView,iItem,3,szDateModified); iItem++; }
HRESULT CDropHandler::CopyDIBV5Data(IDataObject *pDataObject, list<PastedFile_t> *pPastedFileList) { STGMEDIUM stg; HRESULT hr; hr = pDataObject->GetData(&m_ftcDIBV5,&stg); if(hr == S_OK) { BITMAPINFO *pbmp = static_cast<BITMAPINFO *>(GlobalLock(stg.hGlobal)); if(pbmp != NULL) { SYSTEMTIME st; FILETIME ft; FILETIME lft; TCHAR szTime[512]; GetLocalTime(&st); SystemTimeToFileTime(&st,&ft); LocalFileTimeToFileTime(&ft,&lft); CreateFileTimeString(&lft,szTime,SIZEOF_ARRAY(szTime),FALSE); for(int i = 0;i < lstrlen(szTime);i++) { if(szTime[i] == '/') { szTime[i] = '-'; } else if(szTime[i] == ':') { szTime[i] = '.'; } } TCHAR szFullFileName[MAX_PATH]; TCHAR szFileName[MAX_PATH]; /* TODO: Move text into string table. */ StringCchPrintf(szFileName,SIZEOF_ARRAY(szFileName), _T("Clipboard Image (%s).bmp"),szTime); PathCombine(szFullFileName,m_szDestDirectory, szFileName); HANDLE hFile = CreateFile(szFullFileName, GENERIC_WRITE,0,NULL,CREATE_NEW, FILE_ATTRIBUTE_NORMAL,NULL); if(hFile != INVALID_HANDLE_VALUE) { DWORD dwSize = static_cast<DWORD>(sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (GlobalSize(stg.hGlobal) - sizeof(BITMAPINFOHEADER))); LPBYTE pData = new BYTE[dwSize]; BITMAPFILEHEADER *pbfh = (BITMAPFILEHEADER *)pData; /* 'BM'. */ pbfh->bfType = 0x4D42; pbfh->bfSize = pbmp->bmiHeader.biSize; pbfh->bfReserved1 = 0; pbfh->bfReserved2 = 0; pbfh->bfOffBits = sizeof(BITMAPFILEHEADER); BITMAPINFOHEADER *pb5h = (BITMAPINFOHEADER *)(pData + sizeof(BITMAPFILEHEADER)); memcpy(pb5h,&pbmp->bmiHeader,sizeof(BITMAPINFOHEADER)); RGBQUAD *prgb = (RGBQUAD *)(pData + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)); memcpy(prgb,pbmp->bmiColors,GlobalSize(stg.hGlobal) - sizeof(BITMAPINFOHEADER)); DWORD nBytesWritten; WriteFile(hFile,(LPCVOID)pData, dwSize, &nBytesWritten,NULL); CloseHandle(hFile); delete[] pData; PastedFile_t pf; StringCchCopy(pf.szFileName,SIZEOF_ARRAY(pf.szFileName),szFullFileName); PathStripPath(pf.szFileName); pPastedFileList->push_back(pf); } GlobalUnlock(stg.hGlobal); } /* Must release the storage medium. */ ReleaseStgMedium(&stg); } return hr; }
INT_PTR CMergeFilesDialog::OnInitDialog() { m_hDialogIcon = LoadIcon(GetModuleHandle(0),MAKEINTRESOURCE(IDI_MAIN_SMALL)); SetClassLongPtr(m_hDlg,GCLP_HICONSM,reinterpret_cast<LONG_PTR>(m_hDialogIcon)); std::wregex rxPattern; bool bAllMatchPattern = true; rxPattern.assign(_T(".*[\\.]?part[0-9]+"),std::regex_constants::icase); /* If the files all match the pattern .*[\\.]?part[0-9]+ (e.g. document.txt.part1), order them alphabetically. */ for each(auto strFullFilename in m_FullFilenameList) { if(!std::tr1::regex_match(strFullFilename,rxPattern)) { bAllMatchPattern = false; break; } } std::wstring strOutputFilename; if(bAllMatchPattern) { m_FullFilenameList.sort(CompareFilenames); /* Since the filenames all match the pattern, construct the output filename from the first files name. */ rxPattern.assign(_T("[\\.]?part[0-9]+"),std::regex_constants::icase); strOutputFilename = std::tr1::regex_replace(m_FullFilenameList.front(), rxPattern,std::wstring(_T(""))); } else { /* TODO: Improve output name. */ strOutputFilename = _T("output"); } TCHAR szOutputFile[MAX_PATH]; PathCombine(szOutputFile,m_strOutputDirectory.c_str(),strOutputFilename.c_str()); SetDlgItemText(m_hDlg,IDC_MERGE_EDIT_FILENAME,szOutputFile); HWND hListView = GetDlgItem(m_hDlg,IDC_MERGE_LISTVIEW); HIMAGELIST himlSmall; Shell_GetImageLists(NULL,&himlSmall); ListView_SetImageList(hListView,himlSmall,LVSIL_SMALL); SetWindowTheme(hListView,L"Explorer",NULL); ListView_SetExtendedListViewStyleEx(hListView, LVS_EX_DOUBLEBUFFER|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES, LVS_EX_DOUBLEBUFFER|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES); LVCOLUMN lvColumn; TCHAR szTemp[32]; LoadString(GetInstance(),IDS_MERGE_FILES_COLUMN_FILE, szTemp,SIZEOF_ARRAY(szTemp)); lvColumn.mask = LVCF_TEXT; lvColumn.pszText = szTemp; ListView_InsertColumn(hListView,0,&lvColumn); LoadString(GetInstance(),IDS_MERGE_FILES_COLUMN_TYPE, szTemp,SIZEOF_ARRAY(szTemp)); lvColumn.mask = LVCF_TEXT; lvColumn.pszText = szTemp; ListView_InsertColumn(hListView,1,&lvColumn); LoadString(GetInstance(),IDS_MERGE_FILES_COLUMN_SIZE, szTemp,SIZEOF_ARRAY(szTemp)); lvColumn.mask = LVCF_TEXT; lvColumn.pszText = szTemp; ListView_InsertColumn(hListView,2,&lvColumn); LoadString(GetInstance(),IDS_MERGE_FILES_COLUMN_DATE_MODIFIED, szTemp,SIZEOF_ARRAY(szTemp)); lvColumn.mask = LVCF_TEXT; lvColumn.pszText = szTemp; ListView_InsertColumn(hListView,3,&lvColumn); int iItem = 0; for each(auto strFullFilename in m_FullFilenameList) { TCHAR szFullFilename[MAX_PATH]; StringCchCopy(szFullFilename,SIZEOF_ARRAY(szFullFilename), strFullFilename.c_str()); /* TODO: Perform in background thread. */ SHFILEINFO shfi; SHGetFileInfo(szFullFilename,0,&shfi,sizeof(SHFILEINFO), SHGFI_SYSICONINDEX|SHGFI_TYPENAME); LVITEM lvItem; lvItem.mask = LVIF_TEXT|LVIF_IMAGE; lvItem.iItem = iItem; lvItem.iSubItem = 0; lvItem.pszText = szFullFilename; lvItem.iImage = shfi.iIcon; ListView_InsertItem(hListView,&lvItem); ListView_SetItemText(hListView,iItem,1,shfi.szTypeName); WIN32_FILE_ATTRIBUTE_DATA wfad; GetFileAttributesEx(szFullFilename,GetFileExInfoStandard,&wfad); TCHAR szFileSize[32]; ULARGE_INTEGER lFileSize = {wfad.nFileSizeLow,wfad.nFileSizeHigh}; FormatSizeString(lFileSize,szFileSize,SIZEOF_ARRAY(szFileSize)); ListView_SetItemText(hListView,iItem,2,szFileSize); TCHAR szDateModified[32]; CreateFileTimeString(&wfad.ftLastWriteTime,szDateModified, SIZEOF_ARRAY(szDateModified),m_bShowFriendlyDates); ListView_SetItemText(hListView,iItem,3,szDateModified); iItem++; }