code_app/app/demo/device_user.cpp

140 lines
2.8 KiB
C++

#include "device_user.h"
#if 0
DeviceUserMgr::DeviceUserMgr(QWidget *wnd)
{
m_wnd = wnd;
m_twainDSM = nullptr;
HGTwain_CreateDSM((HWND)m_wnd->winId(), &m_twainDSM);
}
DeviceUserMgr::~DeviceUserMgr()
{
HGTwain_DestroyDSM(m_twainDSM);
m_twainDSM = nullptr;
}
class DeviceUser* DeviceUserMgr::OpenDeviceUser()
{
HGTwainDS ds = nullptr;
HGTwain_OpenSelectedDS(m_twainDSM, &ds);
if (nullptr == ds)
return nullptr;
return new DeviceUser(m_wnd, ds);
}
DeviceUser::DeviceUser(QWidget *wnd, HGTwainDS ds)
{
m_wnd = wnd;
m_twainDS = ds;
}
DeviceUser::~DeviceUser()
{
HGTwain_CloseDS(m_twainDS);
m_twainDS = nullptr;
}
QString DeviceUser::GetName()
{
HGChar devName[256];
HGTwain_GetDSName(m_twainDS, devName, 256);
return QString(devName);
}
HGResult DeviceUser::ShowSettingDlg()
{
return HGTwain_EnableDSUIOnly(m_twainDS, (HWND)m_wnd->winId(), DSCloseReqFunc, this);
}
HGResult DeviceUser::StartScan()
{
return HGTwain_EnableDS(m_twainDS, HGFALSE, nullptr, DSCloseReqFunc, this, DSImageFunc, this);
}
void HGAPI DeviceUser::DSCloseReqFunc(HGTwainDS ds, HGPointer param)
{
DeviceUser* p = (DeviceUser*)param;
HGTwain_DisableDS(p->m_twainDS);
}
void HGAPI DeviceUser::DSImageFunc(HGTwainDS ds, HGImage image, HGPointer param)
{
DeviceUser* p = (DeviceUser*)param;
emit p->newImage(image);
}
#else
DeviceUserMgr::DeviceUserMgr(QWidget *wnd)
{
m_wnd = wnd;
m_saneMgr = nullptr;
HGSane_CreateManager("sane.dll", &m_saneMgr);
}
DeviceUserMgr::~DeviceUserMgr()
{
HGSane_DestroyManager(m_saneMgr);
m_saneMgr = nullptr;
}
class DeviceUser* DeviceUserMgr::OpenDeviceUser()
{
HGSaneDevice dev = nullptr;
#ifdef HG_CMP_MSC
HGSane_OpenSelectedDevice(m_saneMgr, (HWND)m_wnd->winId(), &dev);
#else
HGSane_OpenSelectedDevice(m_saneMgr, m_wnd, &dev);
#endif
if (nullptr == dev)
return nullptr;
return new DeviceUser(m_wnd, dev);
}
DeviceUser::DeviceUser(QWidget *wnd, HGSaneDevice dev)
{
m_wnd = wnd;
m_saneDev = dev;
}
DeviceUser::~DeviceUser()
{
HGSane_CloseDevice(m_saneDev);
m_saneDev = nullptr;
}
QString DeviceUser::GetName()
{
HGChar devName[256];
HGSane_GetDeviceName(m_saneDev, devName, 256);
return QString(devName);
}
HGResult DeviceUser::ShowSettingDlg()
{
#ifdef HG_CMP_MSC
return HGSane_ShowDeviceSettingDlg(m_saneDev, (HWND)m_wnd->winId());
#else
return HGSane_ShowDeviceSettingDlg(m_saneDev, m_wnd);
#endif
}
HGResult DeviceUser::StartScan()
{
#ifdef HG_CMP_MSC
return HGSane_StartDeviceWithUI(m_saneDev, (HWND)m_wnd->winId(), DeviceImageFunc, this);
#else
return HGSane_StartDeviceWithUI(m_saneDev, m_wnd, DeviceImageFunc, this);
#endif
}
void HGAPI DeviceUser::DeviceImageFunc(HGSaneDevice dev, HGImage image, HGPointer param)
{
DeviceUser* p = (DeviceUser*)param;
emit p->newImage(image);
}
#endif