⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scanviewerview.cpp

📁 看图软件
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	}
	else if (nChar==VK_ESCAPE) AfxGetApp()->m_pMainWnd->ShowWindow(SW_MINIMIZE);                              //最小化
    
	///////////////////////////////////////////////////////////////////处理上下左右键//////////////////////////////////////////////////////////////////////////
	UINT nIDEvent=15;
	if(nChar==VK_UP)    SetTimer(VK_UP,nIDEvent,NULL);
	if(nChar==VK_DOWN)	SetTimer(VK_DOWN,nIDEvent,NULL);
	if(nChar==VK_LEFT)  SetTimer(VK_LEFT,nIDEvent,NULL);
	if(nChar==VK_RIGHT)	SetTimer(VK_RIGHT,nIDEvent,NULL);
	///////////////////////////////////////////////////////////////////处理上下左右键//////////////////////////////////////////////////////////////////////////

	CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
}


//idcomcn2008
//21:06 2008-1-23
//按下鼠标中键,全屏显示
void CScanViewerView::OnMButtonDown(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND,ID_VIEW_FULLSCREEN,0); 

	CScrollView::OnMButtonDown(nFlags, point);
}


void CScanViewerView::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	::SetCursor (::LoadCursor (::AfxGetInstanceHandle (), MAKEINTRESOURCE(IDC_CUR_LDOWN))) ;
	m_ptLBStartPos=point;	
	m_bDragPhotoState=TRUE;
	SetCapture();

	CScrollView::OnLButtonDown(nFlags, point);
}


//idcomcn2007
//10:33 2007-12-22
//用于鼠标拖动图片
void CScanViewerView::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if (m_bDragPhotoState)
	{
		::SetCursor (::LoadCursor (::AfxGetInstanceHandle (), MAKEINTRESOURCE(IDC_CUR_DRAG))) ;
		OnScrollBy(CSize(-point+m_ptLBStartPos));
		UpdateWindow();
		m_ptLBStartPos=point;	
	}

	CScrollView::OnMouseMove(nFlags, point);
}

void CScanViewerView::OnLButtonUp(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	m_bDragPhotoState=FALSE;
	::ReleaseCapture();

	if (GetDocument()->GetPathName().IsEmpty()) 
		AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND,ID_FILE_OPEN,0);                      //Open Photo file.

	CScrollView::OnLButtonUp(nFlags, point);
}



//idcomcn2007
//0:32 2007-12-9
BOOL CScanViewerView::OnEraseBkgnd(CDC* pDC)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值

	if (!imgShow.IsNull())	return TRUE;
	else return CScrollView::OnEraseBkgnd(pDC);
}



// 多线程遍历目录,返回所有找到的第一张图片,param为字符串指针(为返回值)
UINT CScanViewerView::ThreadFindFirstPhoto(LPVOID param)
{	
	CScanViewerView &pClass=*(CScanViewerView *)param;
	//遍历整个目录树
	CStringArray strFolderArray;	                                        //用于存放目录数组	
	CString szDir=pClass.m_strThreadFindFirstPhoto;                         //获取传入目录                                
	CString strFirstPhotoFullPath;
	BOOL bExistPhotoFile=FALSE;
	
	CFileFind ff;	
	if (szDir.Right(1)!="\\")
	{
		//MessageBox("不相等","信息提示",MB_OK|MB_ICONINFORMATION);
		szDir+="\\";
	}
	szDir+="*.*";
	BOOL res=ff.FindFile(szDir);
	
	while (res)
	{
		res=ff.FindNextFile();
		if (ff.IsDirectory()&&!ff.IsDots())
		{
			//如果是一个子目录,用递归继续往深一层找
			//BrowseDir(ff.GetFilePath());
			strFolderArray.Add(ff.GetFilePath());
		}                              
		else if (!ff.IsDirectory()&&!ff.IsDots())
		{
			//判断是否为图片文件
			if (((CScanViewerApp *)AfxGetApp())->IsPhotoFile(ff.GetFileName()))
			{
				strFirstPhotoFullPath=ff.GetFilePath();
				bExistPhotoFile=TRUE;
				break;
			}
		}

	}
	ff.Close();//关闭

	//如果找到第一个图片,则打开该图片
	if (bExistPhotoFile&&(!strFirstPhotoFullPath.IsEmpty()))
	{		
		TCHAR lpszFileName[MAX_PATH];
		strcpy(lpszFileName,strFirstPhotoFullPath);
		//AfxMessageBox(lpszFileName);
		pClass.GetDocument()->m_bIsFolder=FALSE;
		pClass.SendMessage(WM_MY_MSG_SEARCHFOLDER ,0,( LPARAM )(lpszFileName));  
		if (!strFolderArray.IsEmpty()) strFolderArray.RemoveAll();   //释放资源
		bExistPhotoFile=FALSE;
		return 0;
	}

	int iFolderCount=(int)strFolderArray.GetCount();
	//((CScanViewerApp *)AfxGetApp())->IntegerToStringForTest(1,iFolderCount);
	///////////////////////////////////////////////////////////////////对找到的所有文件夹路径进行排列//////////////////////////////////////////////////////////////////////////
	CString strA,strB,strTemp;
	for (int ia=0;ia<iFolderCount;ia++)
	{
		for (int ib=0;ib<iFolderCount-ia-1;ib++)
		{
			strA=strFolderArray.GetAt(ib);
			strB=strFolderArray.GetAt(ib+1);
			if (strcmp(strA,strB)>0) 
			{
				strTemp=strFolderArray.GetAt(ib);
				strFolderArray.SetAt(ib,strFolderArray.GetAt(ib+1));
				strFolderArray.SetAt(ib+1,strTemp);
			}			
		}
	}
	///////////////////////////////////////////////////////////////////对找到的所有文件夹路径进行排列//////////////////////////////////////////////////////////////////////////
	for (int ia=0;ia<iFolderCount;ia++)
	{
		if (pClass.GetDocument()->m_bIsFolder==FALSE) break;     //如找到第一张图片,则退出循环
		//AfxMessageBox(strFolderArray.GetAt(ia));
		pClass.m_strThreadFindFirstPhoto=strFolderArray.GetAt(ia);
		ThreadFindFirstPhoto(param);
	}


	if (!strFolderArray.IsEmpty()) strFolderArray.RemoveAll();   //释放资源
	bExistPhotoFile=FALSE;
	return 0;
}





//idcomcn2007
//21:47 2005-10-17
//多线程遍历图片文件
//返回所有图片的数目,lpstrDirPath为目录,strENArray为扩展名数组
//定义函数,传入目录路径,把该目录下所有图片路径存储进strPathArray
UINT CScanViewerView::ThreadFindAllPhoto(LPVOID param)
{		
   //遍历整个目录树
	CScanViewerView &pClass=*(CScanViewerView *)param;
	//CScanViewerView *pClass=(CScanViewerView *)param;

	CString strCurrent=pClass.GetDocument()->GetPathName();                 
	strCurrent=strCurrent.Left(strCurrent.ReverseFind('\\'));                       //用于存储当前目录
	//AfxMessageBox(strCurrent);
	if (strCurrent.IsEmpty()) return 0;                                             //如果图片目录路径为空,则返回	
	pClass.m_strPhotoFileArray.RemoveAll();                                         //清空字符数组(数径)


	CString strAppTitleSrc;
	AfxGetMainWnd()->GetWindowText(strAppTitleSrc);                              //获取源程序的标题
	
	int iCountImg=0;
	CFileFind ff;	
	CString strPrompt;

	if (strCurrent.Right(1)!="\\") strCurrent+="\\";	
	strCurrent+="*.*";
	BOOL res=ff.FindFile(strCurrent);

	while (res)
	{
		res=ff.FindNextFile();                             
		if (!ff.IsDirectory()&&!ff.IsDots())
		{
			//比较扩展名
			if (((CScanViewerApp *)AfxGetApp())->IsPhotoFile(ff.GetFileName()))
			{
				iCountImg++;
				pClass.m_strPhotoFileArray.Add(ff.GetFilePath());
			}
			//显示当前访问的文件。			
			CString str;						
			str.Format("正在努力搜索图片文件...\t%s",ff.GetFilePath());		
			AfxGetMainWnd()->SetWindowText(str);                               //更改标题
			//Sleep(10);
		}
	}
	ff.Close();//关闭
	
	AfxGetMainWnd()->SetWindowText(strAppTitleSrc);                            //还原标题


	//在限定的目录查找(上一张或下一张)图片,如找到任一张都退出循环
	//strInput="J:\\my\\my\\";
	//strInput="J:\\my\\";
	//strInput="J:\\";
	strCurrent=pClass.GetDocument()->GetPathName();                 
	strCurrent=strCurrent.Left(strCurrent.ReverseFind('\\'));									    //用于存储当前目录
	if (strCurrent.Right(1)=="\\") strCurrent.Delete(strCurrent.GetLength()-1);					    //删除最后一个'\\'字符
	if (strCurrent.ReverseFind('\\')==-1)                                                           //如果不存在上层目录,则退出
	{
		if (!pClass.m_strPhotoFileArray.IsEmpty())	pClass.PostMessage(WM_MYMSG_UPMYVIEW,0,0);      //发送消息,标记线程完成图片的查找,并打开该图片
		return 0;
	}

	///////////////////////////////////////////////////////////////////遍历当前图片所有上层目录//////////////////////////////////////////////////////////////////////////
	CStringArray strPPArray;	
	CString strParent=strCurrent.Left(strCurrent.ReverseFind('\\'));									    //获取父目录	
	//AfxMessageBox(strParent);
	if (!strPPArray.IsEmpty()) strPPArray.RemoveAll();
	CFileFind fdir;	
	if (strParent.Right(1)!="\\")	strParent+="\\";	
	strParent+="*.*";
	BOOL bResDir=fdir.FindFile(strParent);	 
	while (bResDir)
	{
		bResDir=fdir.FindNextFile();
		if (fdir.IsDirectory()&&!fdir.IsDots())		
		{
			//如果是一个子目录,则存入m_strPhotoFileArray			
			//AfxMessageBox(fdir.GetFilePath());
			strPPArray.Add(fdir.GetFilePath());
		}                              
	}
	fdir.Close();//关闭

	///////////////////////////////////////////////////////////////////遍历当前图片所有上层目录//////////////////////////////////////////////////////////////////////////
	if (strPPArray.IsEmpty()) 
	{
		if (!pClass.m_strPhotoFileArray.IsEmpty())	pClass.PostMessage(WM_MYMSG_UPMYVIEW,0,0);   //发送消息,标记线程完成图片的查找
		return 0;
	}

	//对目录数组按字母大小进行排列,大的后面
	{
		int ilen=(int)strPPArray.GetCount();
		CString strA,strB,strTemp;
		for (int ia=0;ia<ilen;ia++)
		{
			for (int ib=0;ib<ilen-ia-1;ib++)
			{
				strA=CString(strPPArray.GetAt(ib)).MakeLower();
				strB=CString(strPPArray.GetAt(ib+1)).MakeLower();
				if (strcmp(strA,strB)>0) 
				{
					strTemp=strPPArray.GetAt(ib);
					strPPArray.SetAt(ib,strPPArray.GetAt(ib+1));
					strPPArray.SetAt(ib+1,strTemp);
				}	
			}
		}
	}
	//测试用
	//for (int iTemp=0;iTemp<strPPArray.GetCount();iTemp++) AfxMessageBox(strPPArray.GetAt(iTemp));

	int iState=0;                                                                       //找出当前目录在父目录中的位置
	for (int ia=0;ia<strPPArray.GetCount();ia++) if (strCurrent.MakeLower()==CString(strPPArray.GetAt(ia)).MakeLower()) iState=ia;
	
	///////////////////////////////////////////////////////////////////在限定的目录查找(上一张)图片,如找到任一张都退出循环//////////////////////////////////////////////////////////////////////////
	CString strUpwardsImgPath;                                                               //用于上一目录的第一张图片
	if (iState>0)                                                                            //如果当前目录在父目录不为第一张
	{
		for (int ia=iState-1;ia>=0;ia--) 
		{
			//AfxMessageBox(strPPArray.GetAt(ia));
			CFileFind fImg;	
			CString szDir;

			szDir=strPPArray.GetAt(ia);
			if (szDir.Right(1)!="\\") szDir+="\\";	
			szDir+="*.*";
			BOOL res=fImg.FindFile(szDir);

			while (res)
			{
				res=fImg.FindNextFile();
				if (!strUpwardsImgPath.IsEmpty()) break;                               
				if (!fImg.IsDirectory()&&!fImg.IsDots())
				{
					//比较扩展名
					if (((CScanViewerApp *)AfxGetApp())->IsPhotoFile(fImg.GetFileName()))
					{							
							//AfxMessageBox(fImg.GetFilePath());
							strUpwardsImgPath=fImg.GetFilePath();
							break;				
					}
					//Sleep(10);
				}
			}
			fImg.Close();//关闭
		}
	}
	pClass.m_strUpwardsImgPath=strUpwardsImgPath;
	///////////////////////////////////////////////////////////////////在限定的目录查找(上一张)图片,如找到任一张都退出循环//////////////////////////////////////////////////////////////////////////

	///////////////////////////////////////////////////////////////////在限定的目录查找(下一张)图片,如找到任一张都退出循环//////////////////////////////////////////////////////////////////////////
	CString strNextImgPath;                                          //用于下一目录的第一张图片
	if (iState<strPPArray.GetCount()-1)                              //如果当前目录在父目录不为最后
	{
		for (ia=iState+1;ia<strPPArray.GetCount();ia++) 
		{
			//AfxMessageBox(strPPArray.GetAt(ia));
			CFileFind fImg;	
			CString szDir;

			szDir=strPPArray.GetAt(ia);
			if (szDir.Right(1)!="\\") szDir+="\\";	
			szDir+="*.*";
			BOOL res=fImg.FindFile(szDir);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -