📄 setscanner.cpp
字号:
//////////////////////////////////////////////////////////
//还需要待定是否需要
//////////////////////////////////////////////////////////
void CSetScanner::OnAspiInitialize()
{
ASPI32Status=0;
unsigned char AdapterCount=0;
char lpBuffer[40];
ASPI32Status = GetASPI32SupportInfo();
switch(HIBYTE(LOWORD(ASPI32Status)) )
{
case SS_COMP:
AdapterCount = (LOBYTE(LOWORD(ASPI32Status)));
sprintf(lpBuffer,"the number of host is %d",AdapterCount);
MessageBox(lpBuffer,"ASPI for WIN32 test",MB_OK);
break;
default:
MessageBox ( (LPCTSTR) "No ASPI for WIN32 support detected.",
(LPCTSTR) "ASPI for WIN32 test", MB_OK);
}
}
//////////////////////////////////////////////////////////////////////
// 在鼠标单击帮助按钮,调用帮助文档 //
//////////////////////////////////////////////////////////////////////
void CSetScanner::OnButtonHelp()
{
char hhDir[MAX_PATH];
char chmDir[MAX_PATH];
GetWindowsDirectory(hhDir,sizeof(hhDir));
GetWindowsDirectory(chmDir,sizeof(chmDir));
lstrcat(hhDir,"\\twain_32\\mtiscanner\\");
lstrcat(chmDir,"\\twain_32\\mtiscanner\\help.chm");
ShellExecute(m_hWnd, "open", "hh.exe",
chmDir, hhDir, SW_SHOWNORMAL);
}
//////////////////////////////////////////////////////////////////////
//在菜单命令中, 调用帮助文档 // //
//////////////////////////////////////////////////////////////////////
void CSetScanner::OnHelpContent()
{
char hhDir[MAX_PATH];
char chmDir[MAX_PATH];
GetWindowsDirectory(hhDir,sizeof(hhDir));
GetWindowsDirectory(chmDir,sizeof(chmDir));
lstrcat(hhDir,"\\twain_32\\mtiscanner\\");
lstrcat(chmDir,"\\twain_32\\mtiscanner\\help.chm");
ShellExecute(m_hWnd, "open", "hh.exe",
chmDir, hhDir, SW_SHOWNORMAL);
}
//////////////////////////////////////////////////////////////////////
// 菜单中说明当前SCSI接口卡信息框, //
//////////////////////////////////////////////////////////////////////
void CSetScanner::OnScannerGettheinfoofcurrentscsi()
{
MessageBox ( (LPCTSTR) "YTCS扫描仪", (LPCTSTR)"SCSI接口卡",MB_OK);
return;
}
////////////////////////////////////////////////////////////////////////
// 菜单中查看当前扫描仪信息,应该为动态检测,没有测试,以后应该修改 //
////////////////////////////////////////////////////////////////////////
void CSetScanner::OnScannerGettheinfoofcurrentscanner() //WZL?
{
ASPI32Status=0;
SRB_ExecSCSICmd mySRB;
unsigned char AdapterCount=0;
char InquiryBuffer[32];
char lpBuffer[100];
mySRB.SRB_Cmd = SC_EXEC_SCSI_CMD;
mySRB.SRB_HaId = 0;
mySRB.SRB_Flags = SRB_DIR_IN;
mySRB.SRB_Hdr_Rsvd = 0;
mySRB.SRB_Target = 0;
mySRB.SRB_Lun = 0;
mySRB.SRB_BufLen = 36;
mySRB.SRB_SenseLen = SENSE_LEN;
mySRB.SRB_BufPointer= (unsigned char *)InquiryBuffer;
mySRB.SRB_CDBLen = 6;
mySRB.SRB_PostProc = NULL;
mySRB.CDBByte[0] = SCSI_INQUIRY;
mySRB.CDBByte[1] = 0;
mySRB.CDBByte[2] = 0;
mySRB.CDBByte[3] = 0;
mySRB.CDBByte[4] = 36; //原来在这里设置为32,根据新的约定,改为6
mySRB.CDBByte[5] = 0;
ASPI32Status = SendASPI32Command( (LPSRB)&mySRB );
while(mySRB.SRB_Status == SS_PENDING);
switch(mySRB.SRB_Status)
{
case SS_COMP:
sprintf(lpBuffer,"The device on SCSI bus is %s",InquiryBuffer);
MessageBox(lpBuffer,"ASPI for WIN32 test",MB_OK);
break;
default:
MessageBox ( (LPCTSTR) "No ASPI for WIN32 support detected.",
(LPCTSTR) "MTI Data Source", MB_OK);
return;
}
MessageBox( (LPCTSTR) "HIGHDIG XiFei Scanner ",(LPCTSTR) "MTI Tec.", MB_OK);
return;
}
//////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
long CSetScanner::OnMyInitialization(WPARAM wFactor,LPARAM lparam)
{
RunModalLoop( MLF_NOIDLEMSG );
m_bModal = TRUE;
return 0;
}
/////////////////////////////////////////////////////////////////////////
// 本来应该是在菜单中有一个命令,用来退出扫描,这个命令的ID为D_SCANNER_EXIT
// 已经去除了这个命令,可以考虑加上
/////////////////////////////////////////////////////////////////////////void CSetScanner::OnScannerExit()
{
OnOK();
}
void CSetScanner::OnOK()
{
AfxGetApp()->WinHelp(0,HELP_QUIT);
delete m_pSettingsWindow;
delete pScanner;
delete m_pGanWindow;
delete m_pPingqiWindow;
NotifyCloseDSReq();
CDialog::OnOK();
}
void CSetScanner::OnCancel()
{
AfxGetApp()->WinHelp(0,HELP_QUIT);
delete m_pSettingsWindow;
delete pScanner;
delete m_pPositionWindow;
delete m_pGanWindow;
delete m_pPingqiWindow;
NotifyCloseDSReq();
CDialog::OnCancel();
}
/////////////////////////////////////////////////////////////////////////
//响应系统命令,进行窗口拉伸 //
/////////////////////////////////////////////////////////////////////////
void CSetScanner::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
CRect rtClient;
GetClientRect(rtClient);
if (pContainerWnd != NULL)
{
pContainerWnd->MoveWindow
(
0,HEIGHT_TOOLBAR,
rtClient.Width()-SET_WINDOWR,
rtClient.Height() - HEIGHT_TOOLBAR,
TRUE
);
}
}
//////////////////////////////////////////////////////////////
//扫描图像过程
/////////////////////////////////////////////////////////////
void CSetScanner::OnRead2()
{
int row;
//int x;
char str[36];
CString m_sScanType;
GetPrivateProfileString("scan type","type","Twain方式",str,36,InitDir2);
m_sScanType=_T(str);
//确定扫描方式,文件扫描还是TWAIN方式
if(m_sScanType=="Twain扫描") //TWAIN方式
{
//检查底层扫描工作是否准备好,如果好,扫描,否则,查询出错原因,中止扫描
SCSI_TST();
pScanner->m_nDPI= GetPrivateProfileInt("resoultion","reso",300,InitDir2);
row=(int)(((pScanner->m_rtScanZoom).bottom-(pScanner->m_rtScanZoom).top)/FuMian*(pScanner->m_nDPI));
/*if(row>30000)//必须采用文件扫描方式
{
x=MessageBox("图像太大","文件扫描并存储",MB_OKCANCEL);
if(x==IDOK)
{
if(Scan_JZMode()) //下传校正参数
OnReadPicFromDisk(); //文件扫描方式
}
else return;
}
else//采用TWAIN扫描方式*/
{
if(Scan_JZMode()) //==1) //下传校正参数
OnReadPicFromFile(); //Twain扫描
}
}
if(m_sScanType=="文件扫描") //文件扫描方式
{
//检查底层扫描工作是否准备好,如果好,扫描,否则,查询出错原因 ,中止扫描
SCSI_TST();
if(Scan_JZMode()) //下传校正参数参数等
OnReadPicFromDisk(); //文件扫描方式
}
}
///////////////////////////////////////////////////////////////////////
//按照文件方式扫描图像
//当扫描区域长度大于30000个象素点的时候,按照文件扫描方式扫描,存储为两//
//个大小相同的文件,否则,可以选择是Twain扫描还是文件扫描 // //
///////////////////////////////////////////////////////////////////////
void CSetScanner::OnReadPicFromDisk()
{
//int row1,row2;
int row;
int nTop;
//测试,用于扫描起始显示时间
/*time_t date1_t;
time(&date1_t);
int Hour,Minute,Second;
CTime time1(date1_t);*/
pScanner->m_nDPI= GetPrivateProfileInt("resoultion","reso",500,InitDir2);
row =(int)(((pScanner->m_rtScanZoom).bottom-(pScanner->m_rtScanZoom).top)/FuMian*(pScanner->m_nDPI));
int huigui;
char str[36];
CString m_sHuiGuiType;
GetPrivateProfileString("huigui type","type","零点位置",str,36,InitDir2);
m_sHuiGuiType=_T(str);
if(m_sHuiGuiType=="零点位置")
{
huigui=0;
}
if(m_sHuiGuiType=="中间位置")
{
huigui=2;
}
if(m_sHuiGuiType=="静止不动")
{
huigui=1;
}
//判断扫描方式
/*if(row>30000) //大于,图像存储为两个文件
{
row1=row/2;
row2=row-row1;
nTop= (int)((pScanner->m_rtScanZoom).top/FuMian*25.4/0.01);
//调用函数确定第一部分图像的扫描起始点,同时下传SETWINDOWS命令
sendset(nTop,1);
//发送启动扫描
SCSI_Start();
cunchu(row1,0);
//发送结束命令
SCSI_End(0);
//确定第二部分图像的扫描起始点,同时下传SETWINDOWS命令
nTop=(int)(((pScanner->m_rtScanZoom).top/FuMian+row1/(pScanner->m_nDPI))*25.4/0.01);
//调用函数确定第一部分图像的扫描起始点,同时下传SETWINDOWS命令
sendset(nTop,1);
//发送
SCSI_Start();
cunchu(row2,0);
Hour=time1.GetHour();
Minute=time1.GetMinute();
Second=time1.GetSecond();
pTesttime->end(Hour,Minute,Second);
SCSI_End(huigui);
}*/
//else //否则,图像存储为一个文件
{
nTop=(int)((pScanner->m_rtScanZoom).top/FuMian*25.4/0.01);
//调用函数确定第一部分图像的扫描起始点,同时下传SETWINDOWS命令
SetWindow(nTop,1);
//发送启动扫描
SCSI_Start();
cunchu(row,0);
time_t date2_t;
time(&date2_t);
int Hour1,Minute1,Second1;
CTime time2(date2_t);
Hour1=time2.GetHour();
Minute1=time2.GetMinute();
Second1=time2.GetSecond();
pTesttime->end(Hour1,Minute1,Second1);
SCSI_End(huigui);
}
}
////////////////////////////////////////////////////////////////////
////完成图像数据存储过程 //
///////////////////////////////////////////////////////////////////
void CSetScanner::cunchu(int length,int n)
{
CFileException e;
LPCTSTR pFileName ;
BITMAPFILEHEADER Bmpfh;
BITMAPINFOHEADER Bifh;
PALETTEENTRY BMPpalete[256];
int i,j,j1,j2,j3;
int x0,y0,y1,y2; //用来拼齐
int nResolution,nWidth,nLength;
int f=0;
int count;
int downRow;
PSTR lpBits,lp1,lp2,lp3,lp4,lp5,lp6;
DWORD dwBytes, dwBytesInLine, dwBytesBMP;
DWORD dwBytesH, dwBytesInLineH, dwBytesBMPH;
HGLOBAL hMem;
int biBitCount;
int shuzux;
shuzux=GetPrivateProfileInt("Shuzu","shuzu",1200,InitDir2);
ASPI32Status=0xff;
//确定存储文件名称,现在设置是常值,以后需要改为用户输入文件名称
char IniFile[120];
CString s;
static char LastName[] = "Image Files (*.bmp)|*.bmp|All Files (*.*)|*.*|";
GetWindowsDirectory(IniFile,sizeof(IniFile));
CFileDialog m_FileOpen(FALSE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,LastName,NULL);
if(n==0)//文件扫描时候的存储
{
pScanner->m_nDPI= GetPrivateProfileInt("resoultion","reso",500,InitDir2);
pScanner->m_nColor = GetPrivateProfileInt("color num","color",16777216,InitDir2);
if(m_FileOpen.DoModal()==IDOK)
{
s=m_FileOpen.GetPathName();
if(s.Find('.')==-1)
s = s+".bmp";
pFileName=(LPCTSTR)s;
}
else
{
return;
}
}
else //预览时候的存储
{
pFileName=lstrcat(IniFile,"\\twain_32\\MTIScanner\\preview.bmp");
pScanner->m_nDPI=100;
pScanner->m_nColor=16777216;
}
//*******************************************************************//
//以下代码是从SCSI中获取数据,并且存储在响应文件中的过程 //
//*******************************************************************//
nResolution=pScanner->m_nDPI;
int PerMeter;
PerMeter=(int)((nResolution*100)/2.54);
//确定拼色参数
if(pScanner->m_nColor==16777216) //24位彩色图像
{
//分辨率为连续可调时候的拼色参数
//x0表示R和G之间的差距,y0表示R和B之间的差距
int reso1;
x0=0;
y0=0;
reso1=25;
while(pScanner->m_nDPI>reso1)
{
reso1=reso1+50;
x0++;
y0=2*x0;
}
}
else //8位灰度图像和黑白图像的拼齐参数
{
x0=0;
y0=0;
}
//对于灰度和彩色图像是一致的
int pjrow;
// pjrow=(int)(pScanner->m_nDPI/100.0+0.5);
pjrow=(int)(pScanner->m_nDPI/100.0);
y2=pjrow;//表示奇偶差距
y1=y2+y0; //表示需要总的读进来的数据
//计算奇偶数组
shuzu((int)((pScanner->m_rtScanZoom).left/FuMian*shuzux),pScanner->m_nDPI);
//根据扫描区域大小,确定存储文件的格式,为*.BMP
nWidth=(int)((((pScanner->m_rtScanZoom).right-(pScanner->m_rtScanZoom).left)/FuMian*(pScanner->m_nDPI)));
switch(pScanner->m_nColor)
{
case 16777216:
nLength= length+y1;
j1=4-(int)(nWidth*3) % 4 ;
j = (int)(nWidth*24) % 32 ;
if(j==0)
{
dwBytesInLine =(int)(nWidth*24)/8 ;
}
else
{
dwBytesInLine =(int)(nWidth*24)/8;
dwBytesInLine =dwBytesInLine+j1;
}
dwBytesBMP= dwBytes= dwBytesInLine * nLength;
dwBytesBMPH= dwBytesH=dwBytesBMP;
dwBytesInLineH=dwBytesInLine;
break;
case 256:
nLength= length+y1;
j1=4-(nWidth % 4);
j=(int)(nWidth*8) % 32 ;
if(j==0)
{
dwBytesInLine=(nWidth*8)/8 ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -