📄 wiahelpers.cpp
字号:
{
lItemFlags = WiaItemTypeTransfer | WiaItemTypeFile;
//TBD: This function only searches the first level for
// content. It ignores any directories found.
CBasicStringWide cswSearchPath = wszStoragePath;
cswSearchPath += L"\\*.*";
WIN32_FIND_DATA FindData = {0};
HANDLE hFindFile = FindFirstFile(cswSearchPath.String(),&FindData);
if(INVALID_HANDLE_VALUE != hFindFile)
{
do
{
if(!(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
CBasicStringWide cswFileDataPath = wszStoragePath;
cswFileDataPath += L"\\";
cswFileDataPath += FindData.cFileName;
hr = CreateWIAChildItem(FindData.cFileName,
pIWiaMiniDrv,
pChild,
lItemFlags,
WIA_CATEGORY_FINISHED_FILE,
NULL,
cswFileDataPath.String());
if(FAILED(hr))
{
WIAS_ERROR((g_hInst, "Failed to create WIA child storage item, hr = 0x%lx",hr));
break;
}
}
} while(FindNextFile(hFindFile,&FindData));
FindClose(hFindFile);
}
pChild->Release();
pChild = NULL;
}
}
return hr;
}
/**
* This function initializes any root item properties
* needed for this WIA driver.
*
* @param pWiasContext
* Pointer to the WIA item context
* @return
*/
HRESULT InitializeRootItemProperties(
__in BYTE *pWiasContext)
{
HRESULT hr = E_INVALIDARG;
if(pWiasContext)
{
CWIAPropertyManager PropertyManager;
GUID guidItemCategory = WIA_CATEGORY_ROOT;
hr = PropertyManager.AddProperty(WIA_IPA_ITEM_CATEGORY, WIA_IPA_ITEM_CATEGORY_STR, RN, guidItemCategory);
if(FAILED(hr))
{
WIAS_ERROR((g_hInst, "Failed to add WIA_IPA_ITEM_CATEGORY property to the property manager, hr = 0x%lx", hr));
}
if(SUCCEEDED(hr))
{
LONG lDocumentHandlingCapabilities = FEED | DUP | FILM_TPA | STOR;
hr = PropertyManager.AddProperty(WIA_DPS_DOCUMENT_HANDLING_CAPABILITIES,
WIA_DPS_DOCUMENT_HANDLING_CAPABILITIES_STR , RN, lDocumentHandlingCapabilities);
if(FAILED(hr))
{
WIAS_ERROR((g_hInst, "Failed to add WIA_DPS_DOCUMENT_HANDLING_CAPABILITIES property to the property manager, hr = 0x%lx", hr));
}
}
if(SUCCEEDED(hr))
{
LONG lDocumentHandlingStatus = FEED_READY | FILM_TPA_READY | STORAGE_READY;
hr = PropertyManager.AddProperty(WIA_DPS_DOCUMENT_HANDLING_STATUS,
WIA_DPS_DOCUMENT_HANDLING_STATUS_STR, RN, lDocumentHandlingStatus);
if(FAILED(hr))
{
WIAS_ERROR((g_hInst, "Failed to add WIA_DPS_DOCUMENT_HANDLING_STATUS property to the property manager, hr = 0x%lx", hr));
}
}
if(SUCCEEDED(hr))
{
hr = PropertyManager.SetItemProperties(pWiasContext);
if(FAILED(hr))
{
WIAS_ERROR((g_hInst, "CWIAPropertyManager::SetItemProperties failed to set WIA root item properties, hr = 0x%lx",hr));
}
}
else
{
WIAS_ERROR((g_hInst, "Failed to add WIA_IPA_ITEM_CATEGORY property to the property manager, hr = 0x%lx",hr));
}
}
else
{
WIAS_ERROR((g_hInst, "Invalid parameters were passed"));
}
return hr;
}
/**
* This function initializes child item properties
* needed for this WIA driver. The uiResourceID parameter
* determines what image properties will be used.
*
* @param pWiasContext
* Pointer to the WIA item context
* @param hInstance HINSTANCE of the resource location containing uiResourceIDs
* @param uiResourceID
* Resource ID of a bitmap resource loaded as source data
* and a source of WIA item properties.
* FALSE - Child item WIA properties will be added to the item.
* @return
*/
HRESULT InitializeWIAItemProperties(
__in BYTE *pWiasContext,
__in HINSTANCE hInstance,
UINT uiResourceID)
{
HRESULT hr = E_INVALIDARG;
if((pWiasContext)&&(hInstance))
{
//
// Reset the feeder image transfer count:
//
WIA_DRIVER_ITEM_CONTEXT *pWiaDriverItemContext = NULL;
hr = wiasGetDriverItemPrivateContext(pWiasContext, (BYTE**)&pWiaDriverItemContext);
if ((SUCCEEDED(hr)) && (!pWiaDriverItemContext))
{
hr = E_POINTER;
}
if (SUCCEEDED(hr))
{
pWiaDriverItemContext->ulFeederTransferCount = 0;
}
if (SUCCEEDED(hr))
{
CWIAPropertyManager PropertyManager;
Bitmap GDIPlusBitmap(hInstance,MAKEINTRESOURCE(uiResourceID));
LONG lXPosition = 0;
LONG lYPosition = 0;
LONG lXExtent = (LONG)GDIPlusBitmap.GetWidth();
LONG lYExtent = (LONG)GDIPlusBitmap.GetHeight();
LONG lXResolution = 75; // Our sample images are 75 dpi
LONG lYResolution = 75; // Our sample images are 75 dpi
LONG lHorizontalSize = ConvertTo1000thsOfAnInch(lXExtent,lXResolution);
LONG lVerticalSize = ConvertTo1000thsOfAnInch(lYExtent,lYResolution);
LONG lMinHorizontalSize = 1; //0.001"
LONG lMinVerticalSize = 1; //0.001"
LONG lItemType = 0;
//
// Set coordinates for fixed frames
//
if (IDB_FILM == uiResourceID)
{
ULONG ulFrame = NO_FIXED_FRAME;
BSTR bstrItemName = NULL;
// Get the item name
hr = wiasReadPropStr(pWiasContext, WIA_IPA_ITEM_NAME, &bstrItemName, NULL, TRUE);
if (S_OK == hr)
{
if (!lstrcmp(bstrItemName, L"Frame1"))
{
ulFrame = 0;
}
else if (!lstrcmp(bstrItemName, L"Frame2"))
{
ulFrame = 1;
}
else if (!lstrcmp(bstrItemName, L"Frame3"))
{
ulFrame = 2;
}
else if (!lstrcmp(bstrItemName, L"Frame4"))
{
ulFrame = 3;
}
if (ulFrame != NO_FIXED_FRAME)
{
lXPosition = g_FilmFrames[ulFrame].XPOS;
lYPosition = g_FilmFrames[ulFrame].YPOS;
lXExtent = g_FilmFrames[ulFrame].XEXTENT;
lYExtent = g_FilmFrames[ulFrame].YEXTENT;
}
SysFreeString(bstrItemName);
bstrItemName = NULL;
}
}
hr = wiasGetItemType(pWiasContext,&lItemType);
if(SUCCEEDED(hr))
{
if(lItemType & WiaItemTypeGenerated)
{
WIAS_TRACE((g_hInst,"WIA item was created by application."));
}
}
else
{
WIAS_ERROR((g_hInst, "Failed to get the WIA item type, hr = 0x%lx",hr));
}
//
// Add all common item properties first
//
if((lXExtent)&&(lYExtent)&&(lXResolution)&&(lYResolution)&&(lHorizontalSize)&&(lVerticalSize))
{
LONG lAccessRights = WIA_ITEM_READ;
hr = PropertyManager.AddProperty(WIA_IPA_ACCESS_RIGHTS ,WIA_IPA_ACCESS_RIGHTS_STR ,RN,(LONG) 0);
if(SUCCEEDED(hr))
{
LONG lOpticalXResolution = lXResolution;
hr = PropertyManager.AddProperty(WIA_IPS_OPTICAL_XRES ,WIA_IPS_OPTICAL_XRES_STR ,RN,lOpticalXResolution);
}
if(SUCCEEDED(hr))
{
LONG lOpticalYResolution = lYResolution;
hr = PropertyManager.AddProperty(WIA_IPS_OPTICAL_YRES ,WIA_IPS_OPTICAL_YRES_STR ,RN,lOpticalYResolution);
}
if(SUCCEEDED(hr))
{
CBasicDynamicArray<LONG> lPreviewArray;
lPreviewArray.Append(WIA_FINAL_SCAN);
lPreviewArray.Append(WIA_PREVIEW_SCAN);
hr = PropertyManager.AddProperty(WIA_IPS_PREVIEW ,WIA_IPS_PREVIEW_STR ,RWLC,lPreviewArray[0],lPreviewArray[0],&lPreviewArray);
}
if(SUCCEEDED(hr))
{
LONG lShowPreviewControl = WIA_SHOW_PREVIEW_CONTROL;
hr = PropertyManager.AddProperty(WIA_IPS_SHOW_PREVIEW_CONTROL ,WIA_IPS_SHOW_PREVIEW_CONTROL_STR ,RN,lShowPreviewControl);
}
if(SUCCEEDED(hr))
{
//
// Support creation of child items underneath the base flatbed item:
//
BOOL bChildItemCreation = FALSE;
if(uiResourceID == IDB_FLATBED)
{
LONG lItemFlags = 0;
hr = wiasReadPropLong(pWiasContext, WIA_IPA_ITEM_FLAGS, &lItemFlags, NULL, TRUE);
if ((S_OK == hr) && (lItemFlags & WiaItemTypeFolder))
{
bChildItemCreation = TRUE;
}
}
hr = PropertyManager.AddProperty(WIA_IPS_SUPPORTS_CHILD_ITEM_CREATION, WIA_IPS_SUPPORTS_CHILD_ITEM_CREATION_STR, RN, bChildItemCreation);
}
if((uiResourceID == IDB_FLATBED) || (uiResourceID == IDB_FILM))
{
if(SUCCEEDED(hr))
{
hr = PropertyManager.AddProperty(WIA_IPS_MAX_HORIZONTAL_SIZE ,WIA_IPS_MAX_HORIZONTAL_SIZE_STR ,RN,lHorizontalSize);
}
if(SUCCEEDED(hr))
{
hr = PropertyManager.AddProperty(WIA_IPS_MAX_VERTICAL_SIZE ,WIA_IPS_MAX_VERTICAL_SIZE_STR ,RN,lVerticalSize);
}
if(SUCCEEDED(hr))
{
hr = PropertyManager.AddProperty(WIA_IPS_MIN_HORIZONTAL_SIZE ,WIA_IPS_MIN_HORIZONTAL_SIZE_STR ,RN,lMinHorizontalSize);
}
if(SUCCEEDED(hr))
{
hr = PropertyManager.AddProperty(WIA_IPS_MIN_VERTICAL_SIZE ,WIA_IPS_MIN_VERTICAL_SIZE_STR ,RN,lMinVerticalSize);
}
}
else if(uiResourceID == IDB_FEEDER)
{
if(SUCCEEDED(hr))
{
hr = PropertyManager.AddProperty(WIA_IPS_MAX_HORIZONTAL_SIZE ,WIA_IPS_MAX_HORIZONTAL_SIZE_STR ,RN,lHorizontalSize);
}
if(SUCCEEDED(hr))
{
hr = PropertyManager.AddProperty(WIA_IPS_MAX_VERTICAL_SIZE ,WIA_IPS_MAX_VERTICAL_SIZE_STR ,RN,lVerticalSize);
}
if(SUCCEEDED(hr))
{
hr = PropertyManager.AddProperty(WIA_IPS_MIN_HORIZONTAL_SIZE ,WIA_IPS_MIN_HORIZONTAL_SIZE_STR ,RN,lMinHorizontalSize);
}
if(SUCCEEDED(hr))
{
hr = PropertyManager.AddProperty(WIA_IPS_MIN_VERTICAL_SIZE ,WIA_IPS_MIN_VERTICAL_SIZE_STR ,RN,lMinVerticalSize);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -