明月笑刀无情
C++ MFC Windows 应用程序实现:项目名称: CImagePreviewDWORD ev_page_current, ev_page_total;WCHAR ev_current_file[MAX_PATH];void CImagePreview::OnPressPrevButton(){ // TODO: Add your control notification handler code here ev_page_total = GetTotalPages(IMAGE_PATH); WCHAR wszPath[MAX_PATH] = {0}; GetPrevImagePathW(IMAGE_PATH, ev_current_file, wszPath); DisplayImages(wszPath); ev_page_current > 1 ? ev_page_current-- : ev_page_current = 1; SetPageNumber();}void CImagePreview::OnPressNextButton(){ // TODO: Add your control notification handler code here ev_page_total = GetTotalPages(IMAGE_PATH); WCHAR wszPath[MAX_PATH] = {0}; GetNextImagePathW(IMAGE_PATH, ev_current_file, wszPath); DisplayImages(wszPath); ev_page_current < ev_page_total ? ev_page_current++ : ev_page_current = ev_page_total; SetPageNumber();}DWORD CImagePreview::DisplayImage(_In_ WCHAR* wszFilepath){ // You can display image with path. return 0;}DWORD CImagePreview::GetNextImagePathW(_In_ WCHAR* wszFolderpath, _In_ WCHAR* wszFilename, _Out_ WCHAR* wszFilepath){return GetImagePathW(wszFolderpath, wszFilename, wszFilepath, NEXT);}DWORD CImagePreview::GetPrevImagePathW(_In_ WCHAR* wszFolderpath, _In_ WCHAR* wszFilename, _Out_ WCHAR* wszFilepath){return GetImagePathW(wszFolderpath, wszFilename, wszFilepath, PREV);}DWORD CImagePreview::GetImagePathW(_In_ WCHAR* wszFolderpath, _In_ WCHAR* wszInputFilename, _Out_ WCHAR* wszOutputFilepath, _In_ DWORD dwFlag){ WIN32_FIND_DATA t = {0}; HANDLE hFindFile = NULL; BOOL blBreak = FALSE; WCHAR wszFilename[MAX_PATH] = {0}; WCHAR wszFindpath[MAX_PATH] = {0}; WCHAR* wszFindname = NULL; if (wszInputFilename) { if (NULL != wcsstr(wszInputFilename, L"\\")) { wszFindname = wcsrchr(wszInputFilename, L'\\'); wszFindname++; } } // First set folder path. wcscpy_s(wszOutputFilepath, MAX_PATH, wszFolderpath); wcscpy_s(wszFindpath, MAX_PATH, wszFolderpath); wcscat_s(wszFindpath, MAX_PATH, L"*.jpg"); hFindFile = FindFirstFileW(wszFindpath, &t); if (hFindFile == INVALID_HANDLE_VALUE){return GetLastError();} wcscpy_s(wszFilename, MAX_PATH, t.cFileName); if( hFindFile != INVALID_HANDLE_VALUE ) { do { if (t.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){} else { if (NULL != wszFindname && !wcsicmp(wszFindname, t.cFileName)) { if (PREV == dwFlag) break; if (NEXT == dwFlag) {blBreak = TRUE; continue;} if (0 == dwFlag){wcscpy_s(wszFilename, MAX_PATH, t.cFileName); break;} } if (blBreak) break; if(0 == wcslen(wszInputFilename)) {wcscpy_s(wszFilename, MAX_PATH, t.cFileName); break;} wcscpy_s(wszFilename, MAX_PATH, t.cFileName); } } while (FindNextFileW(hFindFile, &t)); } if (blBreak && NEXT == dwFlag) wcscpy_s(wszFilename, MAX_PATH, t.cFileName); FindClose(hFindFile); wcscat_s(wszOutputFilepath, MAX_PATH, wszFilename); return GetLastError();}INT CImagePreview::GetTotalPages(_In_ WCHAR* wszFolderpath){ INT nTotalPage = 0; WIN32_FIND_DATA t = {0}; HANDLE hFindFile = NULL; WCHAR wszFindpath[MAX_PATH] = {0}; wcscpy_s(wszFindpath, MAX_PATH, wszFolderpath); wcscat_s(wszFindpath, MAX_PATH, L"*.jpg"); hFindFile = FindFirstFileW(wszFindpath, &t); if (hFindFile == INVALID_HANDLE_VALUE){return GetLastError();} if( hFindFile != INVALID_HANDLE_VALUE ) { do { if (t.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){} else{nTotalPage++;} } while (FindNextFileW(hFindFile, &t)); } FindClose(hFindFile); return nTotalPage;}VOID CImagePreview::SetPageNumber(void){ CString cstrPage; cstrPage.Format(_T("%d/%d"), ev_page_total, ev_page_current); m_edit_page.SetWindowTextW((LPTSTR)(LPCTSTR)cstrPage); return VOID();}文件的顺序DIR_PATH可以帮助您。我也测试了我的答案,它运行良好。因为你,我刚刚制作了一个电子图片预览器。我认为您不需要更多C #相关的解决方案。我认为它与MFC解决方案相同......怎么样?