📄 caps.cpp
字号:
fix1 = (pTW_FIX32)&(pValRange->MinValue);
fix2 = (pTW_FIX32)&(pValRange->MaxValue);
fix3 = (pTW_FIX32)&(pValRange->StepSize);
sprintf(attribute,"%.6f_to_%.6f,%.6f",FIX32ToFloat(*fix1),FIX32ToFloat(*fix2),FIX32ToFloat(*fix3));
fix1 = (pTW_FIX32)&(pValRange->CurrentValue);
sprintf(current,"%.6f",FIX32ToFloat(*fix1));
fix1 = (pTW_FIX32)&(pValRange->DefaultValue);
sprintf(def,"%.6f",FIX32ToFloat(*fix1));
}
else
{
sprintf(attribute,"%ld_to_%ld,%ld",pValRange->MinValue,pValRange->MaxValue,pValRange->StepSize);
sprintf(current,"%ld",pValRange->CurrentValue);
sprintf(def,"%ld",pValRange->DefaultValue);
}
// store the current and default values
WritePrivateProfileString(capstring,"Current",current,SourceControl);
WritePrivateProfileString(capstring,"Default",def,SourceControl);
GlobalUnlock(pData->hContainer);
lstrcpyn(destination,"Allowed",sizeof(destination));
break;
case TWON_ARRAY:
pValArray = (pTW_ARRAY)GlobalLock(pData->hContainer);
// build the string format [x,y,z...]
memset(attribute,'\0',sizeof(attribute));
lstrcat(attribute,"[");
for (index=0;index<pValArray->NumItems;index++)
{
sprintf(buffer,"%ld",pValArray->ItemList[index]);
lstrcat(attribute,buffer);
lstrcat(attribute,",");
}
// remove last comma
attribute[lstrlen(attribute)-1] = '\0';
lstrcat(attribute,"]");
GlobalUnlock(pData->hContainer);
lstrcpyn(destination,"Allowed",sizeof(destination));
break;
}
// set current to the new cap
WritePrivateProfileString(capstring,destination,attribute,SourceControl);
return(TWRC_SUCCESS);
}
////////////////////////////////////////////////////////////////////////////
// IsCapAllowed -- Checks that the attribute to set is in the Allowed list
// either numerical or enumerated text
//
BOOL IsCapAllowed(TW_INT16 cap, char captext[], char attribute[])
{
char *token;
char buf[30];
char buffer[512];
char IniFile[200];
// make the inifile path
GetWindowsDirectory(IniFile,sizeof(IniFile));
lstrcat(IniFile,"\\twain_32\\MTIscanner\\twacker.ini");
GetPrivateProfileString(captext,"Allowed","",buffer,sizeof(buffer),SourceControl);
// check if within range and on step boundry
// if not on the step boundry, then CHECKSTATUS should be returned after the
// value on the nearest step is set
if (strstr(buffer,"to")!=NULL)
{
// FIX32 change -- the second parameter to the Range is hardcoded for now
if (cap >= (TW_INT16)RangeMinimum(buffer,TWTY_UINT32) && cap <= (TW_INT16)RangeMaximum(buffer,TWTY_UINT32))
{
if (cap % RangeStep(buffer,TWTY_UINT32) == 0)
sprintf(attribute,"%d",cap);
else
{
cap /= (TW_INT16)RangeStep(buffer,TWTY_UINT32);
cap *= (TW_INT16)RangeStep(buffer,TWTY_UINT32);
sprintf(attribute,"%d",cap);
}
return(TRUE);
}
return(FALSE);
}
// make array look like enumerated list (remove brackets)
else
if (strstr(buffer,"[")!=NULL)
memcpy(buffer,&buffer[1],lstrlen(buffer)-1);
// check if in comma delimited list or a onevalue
token = strtok(buffer,",");
while (token != NULL)
{
lstrcpyn(buf,token,sizeof(buf));
if (isalpha(buf[0]))
{
if (cap == (TW_INT16)GetPrivateProfileInt(captext,buf,99,IniFile))
{
lstrcpyn(attribute,buf,sizeof(buf));
return(TRUE);
}
}
else
{
if (cap == (TW_INT16)atoi(buf))
{
lstrcpyn(attribute,buf,sizeof(buf));
return(TRUE);
}
}
token = strtok(NULL,",");
}
return(FALSE);
}
//////////////////////////////////////////////////////////////////////////
// WithinRange --
//
BOOL WithinRange(TW_UINT16 cap, char captext[])
{
return(TRUE);
}
//////////////////////////////////////////////////////////////////////////
// ConvertAttributeToText --
//
void ConvertAttributeToText(TW_UINT32 attrib, char text[], char cap[])
{
char buffer[2048];
char token[30];
int x,y;
char IniFile[200];
// make the inifile path
GetWindowsDirectory(IniFile,sizeof(IniFile));
lstrcat(IniFile,"\\twain_32\\MTIscanner\\twacker.ini");
// the 16 sdk does not support the section command
#ifdef WIN32
GetPrivateProfileSection(cap,buffer,sizeof(buffer),IniFile);
#else
GetPrivateProfileSection16(cap,buffer,sizeof(buffer));
#endif
// if the cap is numerical, there will be no section entry for it in
// the .ini file. Return the number.
if (buffer[0] == '\0')
sprintf(text,"%ld",attrib);
x=0;
memset(token,'\0',sizeof(token));
while(buffer[x] != '\0')
{
y=0;
memset(token,'\0',30);
while(buffer[x] != '=')
{
token[y] = buffer[x];
x++;y++;
}
x++;
if (attrib == (TW_UINT32)atoi(&buffer[x]))
{
lstrcpyn(text,token,sizeof(token));
memset(token,'\0',sizeof(token));
break;
}
while(buffer[x] != '\0')
x++;
x++;
}
}
//////////////////////////////////////////////////////////////////////////
// RangeMinimum -
//
TW_UINT32 RangeMinimum(char attr[],TW_UINT16 ItemType)
{
char *token;
char copy[MAX_TWPATH];
TW_UINT32 value;
TW_FIX32 fix32;
lstrcpy(copy,attr);
token = strtok(copy,"_");
if (ItemType == TWTY_FIX32)
{
fix32 = FloatToFIX32((float)atof(token));
value = *((pTW_UINT32)(&fix32));
return(value);
}
else
return((TW_UINT32)atoi(token));
}
//////////////////////////////////////////////////////////////////////////
// RangeMaximum
//
TW_UINT32 RangeMaximum(char attr[],TW_UINT16 ItemType)
{
char *temp;
char copy[MAX_TWPATH];
TW_UINT32 value;
TW_FIX32 fix32;
lstrcpy(copy,attr);
//在COPY中找子字符串的位置
temp = strstr(copy,"to_");
temp = strtok(temp,",");
temp++;
temp++;
temp++;
if (ItemType == TWTY_FIX32)
{
fix32 = FloatToFIX32((float)atof(temp));
value = *((pTW_UINT32)&fix32);
return(value);
}
else
return((TW_UINT32)atoi(temp));
}
//////////////////////////////////////////////////////////////////////////
// RangeStep
//
TW_UINT32 RangeStep(char attr[],TW_UINT16 ItemType)
{
char *temp;
char copy[MAX_TWPATH];
TW_UINT32 value;
TW_FIX32 fix32;
lstrcpy(copy,attr);
temp = strstr(copy,",");
temp++;
if (ItemType == TWTY_FIX32)
{
fix32 = FloatToFIX32((float)atof(temp));
value = *((pTW_UINT32)&fix32);
return(value);
}
else
return((TW_UINT32)atoi(temp));
}
#ifndef WIN32
/////////////////////////////////////////////////////////////////
// GetPrivateProfileSection16 -- Performs GetPrivateProfileSection
// for a 16 bit application. The function is not defined in the
// 16 bit Win API.
//
void GetPrivateProfileSection16(char cap[], char lineout[],int len)
{
char buffer[512];
char *entry;
char token[40];
int x,pos=0;
char line[40];
char IniFile[MAX_TWPATH];
GetWindowsDirectory(IniFile,sizeof(IniFile));
lstrcat(IniFile,"\\twain_32\\MTIscanner\\twacker.ini");
GetPrivateProfileString(cap,NULL,"",buffer,sizeof(buffer),IniFile);
for(x=0;x<sizeof(buffer);x++)
{
if (buffer[x] == '\0')
{
buffer[x] = ',';
if (buffer[x+1] == '\0')
{
buffer[x] = '\0';
break;
}
}
}
memset(lineout,'\0',len);
entry = strtok(buffer,",");
while(entry != NULL)
{
memset(token,'\0',sizeof(token));
GetPrivateProfileString(cap,entry,"",token,sizeof(token),IniFile);
lstrcpyn(line,entry,sizeof(line));
lstrcat(line,"=");
lstrcat(line,token);
entry = strtok(NULL,",");
memcpy(&lineout[pos],line,lstrlen(line));
//memcpy(dummy,lineout,len);
pos+=lstrlen(line)+1;
}
}
#endif
//////////////////////////////////////////////////////////////////////////////
// FloatToFIX32 -- Convert a floating point value into a FIX32.
//转换FLOAT到FIX32类型
TW_FIX32 FloatToFIX32 (float floater)
{
TW_FIX32 Fix32_value;
char buffer[30];
char *ptr;
sprintf(buffer,"%f",floater);
ptr = strstr(buffer,".");
Fix32_value.Frac = atoi(ptr);
ptr = '\0';
Fix32_value.Whole = atoi(buffer);
//TW_INT32 value = (TW_INT32) (floater * 65536.0 + 0.5);
//Fix32_value.Whole = LOWORD(value >> 16);
//Fix32_value.Frac = LOWORD(value & 0x0000ffffL);
return(Fix32_value);
}
//////////////////////////////////////////////////////////////////////////////
// FIX32ToFloat -- Convert a FIX32 value into a floating point value
//
float FIX32ToFloat (TW_FIX32 fix32)
{
float floater;
floater = (float) fix32.Whole + (float) (fix32.Frac / 65536.0);
return(floater);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -