www.pudn.com > XRayImg.rar > DibGatherStatic.cpp
// DibGatherStatic.cpp : implementation file
//
#include "stdafx.h"
#include "xrayimg.h"
#include "DibGatherStatic.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDibGatherStatic
CDibGatherStatic::CDibGatherStatic()
{
}
CDibGatherStatic::~CDibGatherStatic()
{
}
BEGIN_MESSAGE_MAP(CDibGatherStatic, CStatic)
//{{AFX_MSG_MAP(CDibGatherStatic)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDibGatherStatic message handlers
void CDibGatherStatic::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rcThis;
this->GetClientRect(rcThis);
m_dib.Draw(dc, &rcThis);
// Do not call CStatic::OnPaint() for painting messages
}
void CDibGatherStatic::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
#ifdef _DEBUG
//m_dib=g_theApp.GetDocDibSource();
#endif
CStatic::PreSubclassWindow();
}
//***************************************************************
//函数: 将缓冲区的内容填充到新的dib中
// 1) 建立dib
// 2) 填充数据
// 3) 刷新显示
//
//说明:
//***************************************************************
BOOL CDibGatherStatic::FillDataToDib(int iX, int iY,int nBitCount, UCHAR *pData)
{
BOOL bRst=TRUE;
if( !pData ) return FALSE;
bRst=m_dib.Create(CSize(iX,iY),nBitCount);
if( !bRst )
{
::AfxMessageBox(_T("数据采集失败!"),MB_OK+MB_APPLMODAL+MB_ICONSTOP);
return FALSE;
}
int iXIndex,iYIndex,iBufferIndex;
COLORREF color;
int iBytesPerLine=g_sysSet.nPicWidthBytes;
for(iYIndex=0;iYIndexInvalidate();
return TRUE;
}
//***************************************************************
//函数: 保存文件
// 1) 得到文件全名
// 2) 保存
// 3)
//
//说明:
//***************************************************************
BOOL CDibGatherStatic::SaveToFile(CString sPath)
{
//验证输入的路径
BOOL bRst;
sPath.TrimLeft();
sPath.TrimRight();
if( sPath.Right(1)!=_T("\\") ) sPath+=_T("\\");
if( sPath==_T("\\") || (::GetFileAttributes(sPath)==0XFFFFFFFF) )
{
::AfxMessageBox(_T("无效的文件路径!"),
MB_OK+MB_APPLMODAL+MB_ICONSTOP);
return FALSE;
}
//得到文件日期文件夹
COleDateTime dt;
dt=COleDateTime::GetCurrentTime();
//得到文件夹
CString sFolder,sName,sFilter,sFileName;
sFolder.Format(_T("%02d%02d%02d\\"),dt.GetYear(),dt.GetMonth(),dt.GetDay());
if( ::GetFileAttributes(sPath+sFolder)==0XFFFFFFFF )
{
bRst=CreateDirectory(sPath+sFolder,NULL);;
if( !bRst )
{
::AfxMessageBox(_T("无效的文件路径!"),MB_OK+MB_APPLMODAL+MB_ICONSTOP);
return FALSE;
}
}
//文件名称 后缀
sName.Format(_T("%02d%02d%02d"),dt.GetHour(),dt.GetMinute(),dt.GetSecond());
sFilter.LoadString(IDS_FILE_TYPE);
CFileFind find;
while( TRUE )
{
//得到文件名称
sFileName=sPath+sFolder+sName+sFilter;
//保存文件
bRst=find.FindFile(sFileName);
if( !bRst )
{
bRst=m_dib.Save(sFileName);
break;
}
sName+=_T("_1");
continue;
}
find.Close();
if( !bRst ) ::AfxMessageBox(_T("文件保存失败!"),
MB_OK+MB_APPLMODAL+MB_ICONSTOP);
return bRst;
}