猿问

C# 和 C++ MFC:使用文件夹文件计数和顺序创建书页

我想开发一个执行分页功能的模块,以便可以像电子书一样查看任意文件夹中的图片。
我正在尝试使用C #and实现接口和功能C++ MFC

界面:

文件总数不固定。


示例:


+Folder : images

|_  image_01.jpg  

|_  image_02.jpg  

|_  image_03.jpg  


Total page : 3 (If an image is created in the folder:"images", Total page will be 4.)   

Current page : 2 (image_02.jpg)  

如果我按<<PREV( NEXT>>),应用程序将显示image_01.jpg( image_03.jpg)。


不幸的是我不知道。我该如何实施?


我无法描述代码,因为我在互联网上找不到解决方案。请不要投票反对并教我如何做。


提前谢谢你。


如果你解决了任何一个C # Windows Form Application和C ++ MFC Application solutions,我肯定会投票。


如果您能同时发布两个解决方案,我将不胜感激。


慕容3067478
浏览 214回答 1
1回答

明月笑刀无情

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