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

📄 picimgdlg.cpp

📁 基于EVC开发的图片集文件浏览和图片浏览为一体的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	}
	else
	{
        CString strname = m_curfile;
		CString strpath;
		CString fullformat;
		CString fixname;
		CString lastname;
		int i;
		i = strname.ReverseFind('\\');
		strpath = strname.Left( i );
		fullformat = strpath + "\\*.*";
        WIN32_FIND_DATA fd;
		HANDLE hFind = FindFirstFile(fullformat,&fd);
		lastname = strpath + "\\" + fd.cFileName;    //把第一个值给lastname,防止到第一个值时出错。
		int a = TRUE;
		while((hFind != INVALID_HANDLE_VALUE) &&a)
		{
			if( wcscmp( m_curfile,strpath + "\\" + fd.cFileName ) )
			{
				splitpath ( fd.cFileName, fixname );
				fixname.MakeLower();
				if ( !wcscmp ( fixname, _T(".jpg") ) || !wcscmp ( fixname, _T(".bmp") ) )
					lastname = strpath + "\\" + fd.cFileName;
				a = ::FindNextFile(hFind,&fd); //a是判断是否还有文件.
			}
			else
			{
				m_curfile = lastname;
				a = FALSE;
			}
		}
		FindClose(hFind);
		ShowImage();
	}
	return TRUE;
}

void CPicImgDlg::OnZoomin() 
{
	switch (m_rate)
	{
		case 250 : 
			m_rate = 500;
			break;
		case 500 : 
			m_rate = 750;
			break;
		case 750 : 
			m_rate = 1000;
			break;
		case 1000 : 
			m_rate = 1500;
			break;
		case 1500 : 
			m_rate = 2000;
			break;
		case 2000 : 
			m_rate = 4000;
			break;
		case 4000 : 
			m_rate = 4000;
			return;
	}
	if (m_fullflag)
		RedrawWindow();
	else
		RedrawWindow(&m_rtimage);

}

void CPicImgDlg::OnZoomout() 
{
	switch (m_rate)
	{
		case 250 : 
			return;
		case 500 : 
			m_rate = 250;
			break;
		case 750 : 
			m_rate = 500;
			break;
		case 1000 : 
			m_rate = 750;
			break;
		case 1500 : 
			m_rate = 1000;
			break;
		case 2000 : 
			m_rate = 1500;
			break;
		case 4000 : 
			m_rate = 2000;
			return;
	}
	if (m_fullflag)
		RedrawWindow();
	else
		RedrawWindow(&m_rtimage);

}

int CPicImgDlg::ShowImage()
{
	HBITMAP ret = ImgConvert(m_curfile);
    m_filename = m_curfile;
	if (ret!= NULL)
	{
		if (m_curbmpptr != NULL)
		{
			delete m_curbmpptr;
			m_curbmpptr = NULL;
		}
        //得到想显示的图片指针
		m_curbmpptr = CBitmap::FromHandle(ret);
		CloseHandle(ret);
		BITMAP bm;
		m_curbmpptr->GetObject(sizeof(bm), &bm);
		ifullheight = 480;
		ifullwidth = 640;
		//这里是不是有些问题。
		if ((bm.bmWidth >640 ) || (bm.bmHeight >480 ))
		{
			if ((640 * 1000/bm.bmWidth ) < (480 * 1000/bm.bmHeight ))
				ifullheight = bm.bmHeight * 640 /bm.bmWidth;
			else
				ifullwidth = bm.bmWidth * 480 /bm.bmHeight;
		}

		iareawidth=m_rtimage.Width();
		iareaheight=m_rtimage.Height();

		if ((bm.bmWidth >m_rtimage.Width() ) || (bm.bmHeight >m_rtimage.Height() ))
		{
			if ((m_rtimage.Width() * 1000/bm.bmWidth ) <(m_rtimage.Height() * 1000/bm.bmHeight ))
				iareaheight = bm.bmHeight * m_rtimage.Width() /bm.bmWidth;
			else
				iareawidth = bm.bmWidth * m_rtimage.Height() /bm.bmHeight;
		}

		if (m_fullflag)
		{
			RedrawWindow();
		}
		else
		{
			RedrawWindow(&m_rtimage);
			RedrawWindow(&m_rtname);
		}

	}
//	else 
//		RedrawWindow();
	return 0;
}


void CPicImgDlg::splitpath(CString path, CString &ext)
{
	int i;
	CString str1;
	CString str2;
    str1 = path;
	i = str1.ReverseFind('.');
	str2 = str1.Right( str1.GetLength() - i  );
	ext = str2;
}

CPicImgDlg::~CPicImgDlg()
{
	if (m_curbmpptr != NULL)
	{
		delete m_curbmpptr;
		m_curbmpptr = NULL;
	}
	//关闭按键灯
	if( INVALID_HANDLE_VALUE == m_light )
	{
		return;
	}
	CloseHandle(m_light);
}

void CPicImgDlg::OnBack() 
{
	// TODO: Add your control notification handler code here
	OnOK();
	
}

void CPicImgDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
	if(!m_fullflag)
	{
		// TODO: Add your message handler code here and/or call default
		if(InRect(m_rtfullscreen.left,m_rtfullscreen.top,m_rtfullscreen.right,m_rtfullscreen.bottom,point.x,point.y))
			OnFullscreen();
		if(InRect(m_rtzoomout.left,m_rtzoomout.top,m_rtzoomout.right,m_rtzoomout.bottom,point.x,point.y))
			OnZoomout();
		if(InRect(m_rtzoomin.left,m_rtzoomin.top,m_rtzoomin.right,m_rtzoomin.bottom,point.x,point.y))
			OnZoomin();
		if(InRect(m_rtprv.left,m_rtprv.top,m_rtprv.right,m_rtprv.bottom,point.x,point.y))
			OnPrevious();
		if(InRect(m_rtnext.left,m_rtnext.top,m_rtnext.right,m_rtnext.bottom,point.x,point.y))
			OnNext();
		if(InRect(m_rtopen.left,m_rtopen.top,m_rtopen.right,m_rtopen.bottom,point.x,point.y))
			OnList();
		if(InRect(m_rtclose.left,m_rtclose.top,m_rtclose.right,m_rtclose.bottom,point.x,point.y))
			OnBack();
		if(InRect(m_rthelp.left,m_rthelp.top,m_rthelp.right,m_rthelp.bottom,point.x,point.y))
			OnHelp();
	}
	else
	{
		OnFullscreen();
	}
		

	CDialog::OnLButtonUp(nFlags, point);
}

BOOL CPicImgDlg::InRect(int left, int top, int right, int bottom, int px, int py)
{
	if((left < 0) || (left > 640))
		return FALSE;
	if((right < 0) || (right > 640))
		return FALSE;
	if((top < 0) || (top > 480))
		return FALSE;
	if((bottom < 0) || (bottom > 480))
		return FALSE;
	if((px < 0) || (px > 640))
		return FALSE;
	if((py < 0) || (py > 480))
		return FALSE;

	if((px>=left)&&(px<=right) && (py>=top)&&(py<=bottom))
		return TRUE;
	return FALSE;

}

BOOL CPicImgDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (pMsg->message == WM_KEYDOWN)
	{
		if( pMsg->wParam == VK_6 )
		{
			HWND hand;
			BOOL proc = FALSE;
			hand = ::FindWindow( NULL,_T("cstgps") );  
			if( hand )
			{
				proc = ::SetForegroundWindow(hand);
			}
		}
		else if( pMsg->wParam == VK_5 )
		{
			SetTimer(1188,200,NULL);
			if( m_signal )
			{
				m_signal = FALSE;
				OnPrevious();
			}			
		}

		else if( pMsg->wParam == VK_4 )
		{
			SetTimer(1188,200,NULL);
			if( m_signal )
			{
				m_signal = FALSE;
				OnNext();
			}
		}

		else if( pMsg->wParam == VK_1 )
		{
			SetTimer(1188,200,NULL);
			if( m_signal )
			{
				m_signal = FALSE;
				OnZoomout();
			}				
		}

		else if( pMsg->wParam == VK_3 )
		{
			SetTimer(1188,200,NULL);
			if( m_signal )
			{
				m_signal = FALSE;
				OnZoomin();
			}			
		}
		else if( pMsg->wParam == VK_0 )
		{
			OnFullscreen();
		}
		else if( pMsg->wParam == VK_2 )
		{
			OnList();
		}
		else if( pMsg->wParam == VK_7 )
		{
			SetTimer(1188,200,NULL);
			if( m_signal )
			{
				m_signal = FALSE;
				OnOK();
			}				
		}
		//开键盘灯
		m_light = CreateFile(L"DSK2:",GENERIC_READ|GENERIC_WRITE,0,NULL,
						   OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
		if( INVALID_HANDLE_VALUE == m_light )
		{
			return FALSE;
		}
		SetTimer(1128,10000,NULL);
	}
	return CDialog::PreTranslateMessage(pMsg);
}

void CPicImgDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if ( nIDEvent == 1188 )
	{
		m_signal = TRUE;
		KillTimer(1188);
	}
	else if ( nIDEvent == 1128 )
	{
		if( INVALID_HANDLE_VALUE == m_light )
		{
			return;
		}
		CloseHandle(m_light);
	}
	else if ( nIDEvent == 88 )
	{
		ShowImage();
		KillTimer(88);
	}

	CDialog::OnTimer(nIDEvent);
}

void CPicImgDlg::OnHelp() 
{
	// TODO: Add your control notification handler code here
	Help myhelp;
	myhelp.DoModal();
}

CString CPicImgDlg::GetFirstName()
{
	CString strname = m_curfile;
	CString strpath;
	CString fullformat;
	CString fixname;
	CString firstname;
	int i;
	i = strname.ReverseFind('\\');
	strpath = strname.Left( i );
	fullformat = strpath + "\\*.*";
	WIN32_FIND_DATA fd;
	HANDLE hFind = FindFirstFile(fullformat,&fd);
	int a = TRUE;
	while((hFind != INVALID_HANDLE_VALUE) &&a)
	{		
		splitpath ( fd.cFileName, fixname );
		fixname.MakeLower();
		if ( !wcscmp ( fixname, _T(".jpg") ) || !wcscmp ( fixname, _T(".bmp") ) )
		{
			a = FALSE;
			firstname = strpath + "\\" + fd.cFileName;
		}
		else
			a = ::FindNextFile(hFind,&fd);		
	}
	FindClose(hFind);

	return firstname;
}

CString CPicImgDlg::GetLastName()
{
	CString strname = m_curfile;
	CString strpath;
	CString fullformat;
	CString fixname;
	CString lastname = "";
	int i;
	i = strname.ReverseFind('\\');
	strpath = strname.Left( i );
	fullformat = strpath + "\\*.*";
    WIN32_FIND_DATA fd;
	HANDLE hFind = FindFirstFile(fullformat,&fd);
	int a = TRUE;
	while((hFind != INVALID_HANDLE_VALUE) &&a)
	{		
		//在这里判断是不是最后一幅.
		splitpath ( fd.cFileName, fixname );
		fixname.MakeLower();
		if ( !wcscmp ( fixname, _T(".jpg") ) || !wcscmp ( fixname, _T(".bmp") ) )
			lastname = strpath + "\\" + fd.cFileName;
		a = ::FindNextFile(hFind,&fd);
	}
	FindClose(hFind);

	return lastname;
}

⌨️ 快捷键说明

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