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

📄 scanviewerview.cpp

📁 看图软件
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	{
		int ia=0;
		BOOL bEquation=FALSE;
		for (ia=0;ia<m_strPhotoFileArray.GetCount();ia++) if (strPathName==m_strPhotoFileArray.GetAt(ia)) bEquation=TRUE;
		if (!bEquation)
			SearchFolder();
	}
	///////////////////////////////////////////////////////////////////遍历图片//////////////////////////////////////////////////////////////////////////
}


// CScanViewerView 打印

BOOL CScanViewerView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// 默认准备
	return DoPreparePrinting(pInfo);
}

void CScanViewerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 打印前添加额外的初始化
}

void CScanViewerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 打印后添加清除过程
}


// CScanViewerView 诊断

#ifdef _DEBUG
void CScanViewerView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CScanViewerView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CScanViewerDoc* CScanViewerView::GetDocument() const // 非调试版本是内联的
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CScanViewerDoc)));
	return (CScanViewerDoc*)m_pDocument;
}
#endif //_DEBUG


// CScanViewerView 消息处理程序


//idcomcn2008
//1:03 2008-5-22
//传入全路径名,获取文件名(不包路径和扩展名),
CString CScanViewerView::GetPhotoFileTitle(CString strFullPathName)
{
	CString strReturnValue;

	strReturnValue=strFullPathName.Mid(strFullPathName.ReverseFind('\\')+1);
	if (strReturnValue.Find('.')!=-1) 
		strReturnValue=strReturnValue.Left(strReturnValue.ReverseFind('.'));

	return strReturnValue;
}


//idcomcn2008
//21:40 2008-1-20
//按字母大小进行排列,大的后面(不包含扩展名)
void CScanViewerView::PhotoRange(CStringArray& strPathArray)
{
	if (strPathArray.IsEmpty()) return;
	int ia=0,ib=0,ilen=(int)strPathArray.GetCount();
	

	//进行排列
	CString strA,strB,strTemp;
	for (int ia=0;ia<ilen;ia++)
	{
		for (int ib=0;ib<ilen-ia-1;ib++)
		{
			strA=GetPhotoFileTitle(CString(strPathArray.GetAt(ib)).MakeLower());							
			strB=GetPhotoFileTitle(CString(strPathArray.GetAt(ib+1)).MakeLower());
			if (strcmp(strA,strB)>0) 
			{
				strTemp=strPathArray.GetAt(ib);
				strPathArray.SetAt(ib,strPathArray.GetAt(ib+1));
				strPathArray.SetAt(ib+1,strTemp);
			}			
		}
	}

}

//idcomcn2008
//21:40 2008-1-20
//按数字大小进行排列,大的后面
void CScanViewerView::PhotoNumberRange(CStringArray& strPathArray)
{
	if (strPathArray.IsEmpty()) return;

	//如果任一不为数字,则退出
	CString strIsNumber;
	for (int ia=0;ia<strPathArray.GetCount();ia++)
	{
		strIsNumber=GetPhotoFileTitle(CString(strPathArray.GetAt(ia)).MakeLower());		
		if (atoi(strIsNumber)==0) return; 
		//AfxMessageBox(strIsNumber);
	}


	//转为数字,并排列
	CString strToNumberA,strToNumberB,strTemp;
	for (int ia=0;ia<strPathArray.GetCount();ia++)
	{
		for (int ib=0;ib<strPathArray.GetCount()-ia-1;ib++)
		{
			strToNumberA=GetPhotoFileTitle(CString(strPathArray.GetAt(ib)).MakeLower());							
			strToNumberB=GetPhotoFileTitle(CString(strPathArray.GetAt(ib+1)).MakeLower());
			if (atoi(strToNumberA)>atoi(strToNumberB)) 
			{
				strTemp=strPathArray.GetAt(ib);
				strPathArray.SetAt(ib,strPathArray.GetAt(ib+1));
				strPathArray.SetAt(ib+1,strTemp);
			}			
		}
	}
}



//idcomcn2008
//23:08 2008-6-5
//遍历该目录
void CScanViewerView::SearchFolder()
{
	if (!m_strPhotoFileArray.IsEmpty()) m_strPhotoFileArray.RemoveAt(0);
	AfxBeginThread(ThreadFindAllPhoto, this, THREAD_PRIORITY_NORMAL);            //前两个参数分别是函数名以及我传入的目标窗口句柄	
}



//idcomcn2007
//0:05 2007-10-11
//用户自定义消息函数,找到第一张图片,在此打开图片,
LRESULT CScanViewerView::MSGOpenFirstPhoto(WPARAM wParam, LPARAM lParam)
{
	//AfxMessageBox((LPTSTR)lParam);
	AfxGetApp()->OpenDocumentFile((LPTSTR)lParam);
	
	return 0;
}



//idcomcn2007
//0:05 2007-10-11
//用户自定义消息函数,打开图片,更新视图
LRESULT CScanViewerView::MSGUpdateMyView(WPARAM wParam, LPARAM lParam)
{

	if (!(m_strPhotoFileArray.IsEmpty()))
	{			
		PhotoRange(m_strPhotoFileArray);                //按字母大小进行排列,大的后面(不包含扩展名)
		PhotoNumberRange(m_strPhotoFileArray);          //按数字大小进行排列,大的后面
		int ia=0;
		BOOL bEquation=FALSE;
		for (ia=0;ia<m_strPhotoFileArray.GetCount();ia++) if (GetDocument()->GetPathName()==m_strPhotoFileArray.GetAt(ia)) bEquation=TRUE;
		if (!bEquation)
		{
			AfxGetApp()->OpenDocumentFile(m_strPhotoFileArray.GetAt(0));
		}
	}
	return 0;
}

//idcomcn2007
//19:52 2007-12-22
//把图片路径传入CImage( imgShow)对象中
void CScanViewerView::BuildImage(LPCTSTR pszFileName)
{		
	if (CString(pszFileName).IsEmpty()) return;

	//转换到宽字符
	LPWSTR lpwfilename=new WCHAR[MAX_PATH];
	memset(lpwfilename,0,sizeof(WCHAR)*MAX_PATH);
	MultiByteToWideChar(CP_ACP,
                     MB_PRECOMPOSED,                    // character-type options
                     pszFileName,                       // address of string to map
                     CString(pszFileName).GetLength(),  // number of bytes in string
                     lpwfilename,                       // address of wide-character buffer
                     MAX_PATH);                         //必须先转换到宽字符,否则后面调用的时候,结果会不对!

	CRect rectClient;
	GetClientRect(&rectClient);	 

	Bitmap* pImgTemp;
	pImgTemp=Bitmap::FromFile(lpwfilename);//打开图片	

	switch(m_enClockwiseRotate)
	{
	case CLOCKWISE_ROTATE_0:                                        //顺时针方向旋转0度
		pImgTemp->RotateFlip(RotateNoneFlipNone);
		break;
	case CLOCKWISE_ROTATE_90:                                       //顺时针方向旋转180度
		pImgTemp->RotateFlip(Rotate90FlipNone);
		break;
	case CLOCKWISE_ROTATE_180:                                      //顺时针方向旋转90度
		pImgTemp->RotateFlip(Rotate180FlipNone);
		break;
	case CLOCKWISE_ROTATE_270:                                      //顺时针方向旋转270度
		pImgTemp->RotateFlip(Rotate270FlipNone);
		break;
	default:
		break;
	}

	UINT unTWidth=pImgTemp->GetWidth();
	UINT unTHeight=pImgTemp->GetHeight();	
	//((CScanViewerApp *)AfxGetApp())->IntegerToStringForTest(2,unTWidth,unTHeight);
	if (!imgShow.IsNull())	imgShow.Destroy();	
	switch(m_enViewSize)
	{
	case FULL_SIZE:                                    //实际大小
		{
			UINT unTW=unTWidth,unTH=unTHeight;
			imgShow.Create(unTW,unTH,32);			
			HDC hDCimg=imgShow.GetDC();
			Graphics grpShow(hDCimg);			
			grpShow.DrawImage(pImgTemp, 0, 0,unTW,unTH);
			grpShow.ReleaseHDC(hDCimg);                //要记得relese,GDI都需要释放,否则资源会被占用而不接受其他操作	
			imgShow.ReleaseDC();                       //ReleaseDC for each call to GetDC.
		}
		break;
	case EQUAL_SIZE:                                   //合适大小
		{
			UINT unTW=unTWidth,unTH=unTHeight;
			if ((UINT)rectClient.Width()<unTWidth) {unTW=rectClient.Width();unTH=rectClient.Width()*unTHeight/unTWidth;}
			if ((UINT)rectClient.Height()<unTH) {unTW=rectClient.Height()*unTW/unTH;unTH=rectClient.Height();}
			imgShow.Create(unTW,unTH,32);			
			HDC hDCimg=imgShow.GetDC();
			Graphics grpShow(hDCimg);			
			grpShow.DrawImage(pImgTemp, 0, 0,unTW,unTH);
			grpShow.ReleaseHDC(hDCimg);                  //要记得relese,GDI都需要释放,否则资源会被占用而不接受其他操作	
			imgShow.ReleaseDC();                         //ReleaseDC for each call to GetDC.			
		}
		break;
	case EQUAL_WIDTH:                                  //合适宽度
		{
			UINT unTW=unTWidth,unTH=unTHeight;
			if ((UINT)rectClient.Width()<unTWidth) {unTW=rectClient.Width();unTH=rectClient.Width()*unTHeight/unTWidth;}
			imgShow.Create(unTW,unTH,32);			
			HDC hDCimg=imgShow.GetDC();
			Graphics grpShow(hDCimg);			
			grpShow.DrawImage(pImgTemp, 0, 0,unTW,unTH);
			grpShow.ReleaseHDC(hDCimg);                  //要记得relese,GDI都需要释放,否则资源会被占用而不接受其他操作	
			imgShow.ReleaseDC();                         //ReleaseDC for each call to GetDC.			
		}
		break;
	case EQUAL_HEIGHT:                                 //合适高度
		{
			UINT unTW=unTWidth,unTH=unTHeight;
			if ((UINT)rectClient.Height()<unTHeight) {unTW=rectClient.Height()*unTWidth/unTHeight;unTH=rectClient.Height();}
			imgShow.Create(unTW,unTH,32);			
			HDC hDCimg=imgShow.GetDC();
			Graphics grpShow(hDCimg);			
			grpShow.DrawImage(pImgTemp, 0, 0,unTW,unTH);
			grpShow.ReleaseHDC(hDCimg);                  //要记得relese,GDI都需要释放,否则资源会被占用而不接受其他操作	
			imgShow.ReleaseDC();                         //ReleaseDC for each call to GetDC.			
		}
		break;
	}
    delete lpwfilename;
	delete pImgTemp;
	AfxGetMainWnd()->Invalidate();		                 // 强制更新窗口大小	
}


//idcomcn2007
//21:39 2007-12-20
//自定义滚动
UINT CScanViewerView::ThreadCustomRoll(LPVOID param)
{
	int icount=0,isam=5;
	UINT &nSBCode=*(UINT *)param;		
	if(VK_UP==nSBCode)   	for (icount = 0 ; icount < isam ; icount++) AfxGetMainWnd()->SendMessage(WM_VSCROLL, SB_LINEUP , NULL) ;
	if(VK_DOWN==nSBCode)	for (icount = 0 ; icount < isam ; icount++) AfxGetMainWnd()->SendMessage(WM_VSCROLL, SB_LINEDOWN , NULL) ;
	if(VK_LEFT==nSBCode)   	for (icount = 0 ; icount < isam ; icount++) AfxGetMainWnd()->SendMessage(WM_HSCROLL, SB_LINELEFT , NULL) ;
	if(VK_RIGHT==nSBCode)	for (icount = 0 ; icount < isam ; icount++) AfxGetMainWnd()->SendMessage(WM_HSCROLL, SB_LINERIGHT , NULL) ;
	return 0;
}


void CScanViewerView::OnTimer(UINT nIDEvent)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if (nIDEvent==VK_UP)
	{
		 m_nThreadCustomRoll=VK_UP;  
		 if (GetAsyncKeyState(VK_UP)<0)	 AfxBeginThread(ThreadCustomRoll,&m_nThreadCustomRoll, THREAD_PRIORITY_NORMAL);
		 else  KillTimer(VK_UP);
	}
	if (nIDEvent==VK_DOWN)
	{
		m_nThreadCustomRoll=VK_DOWN;  
		if (GetAsyncKeyState(VK_DOWN)<0) AfxBeginThread(ThreadCustomRoll,&m_nThreadCustomRoll, THREAD_PRIORITY_NORMAL);
		else  KillTimer(VK_DOWN);
	}
	if (nIDEvent==VK_LEFT)
	{
		m_nThreadCustomRoll=VK_LEFT;  
		if (GetAsyncKeyState(VK_LEFT)<0) AfxBeginThread(ThreadCustomRoll,&m_nThreadCustomRoll, THREAD_PRIORITY_NORMAL);
		else  KillTimer(VK_LEFT);
	}
	if (nIDEvent==VK_RIGHT)
	{
		m_nThreadCustomRoll=VK_RIGHT;  
		if (GetAsyncKeyState(VK_RIGHT)<0) AfxBeginThread(ThreadCustomRoll,&m_nThreadCustomRoll, THREAD_PRIORITY_NORMAL);
		else  KillTimer(VK_RIGHT);
	}

	CScrollView::OnTimer(nIDEvent);
}


//idcomcn2007
//13:57 2007-12-8
void CScanViewerView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if(nChar==0x44)	    AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND,ID_DIR_OPEN,0);                                                           
	if(nChar==0x4E)	    AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND,ID_FILE_NEW,0);                       //N Key New document
	if(nChar==0x4F)	    AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND,ID_FILE_OPEN,0);                      //O键打开现有文件
	if(nChar==0x54)	    AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND,ID_SHOWTIME,0);                       //T键显示当前时间
	if(nChar==0x50)	    AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND,ID_SHOWPATH,0);                       //P Show Path Name
	if(nChar==0x46)	    AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND,ID_VIEW_FULLSCREEN,0);                //FKey Full Screen
	if(nChar==VK_F11)   AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND,ID_VIEW_FULLSCREEN,0);                //F11Key Full Screen
	if((nChar==VK_ESCAPE)&&!(AfxGetApp()->m_pMainWnd->GetStyle()&WS_CAPTION))                                 //Esc Key Full Screen
	{
		AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND,ID_VIEW_FULLSCREEN,0);                                                                                    
		AfxGetApp()->m_pMainWnd->ShowWindow(SW_MINIMIZE);		                                              //最小化

⌨️ 快捷键说明

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