twain2/MFC_UI.cpp

127 lines
2.5 KiB
C++

#include "stdafx.h"
#include "MFC_UI.h"
#include "TwainUIDlg.h"
#include "IndicatorDlg.h"
#include "hugaotwainds.h"
#include "Resource.h"
extern ChugaotwaindsApp theApp;
void DeleteWnd(CDialog* pWnd)
{
if (pWnd && pWnd->GetSafeHwnd())
{
pWnd->DestroyWindow();
delete pWnd;
}
}
MFC_UI::MFC_UI(CTWAINDS_FreeImage *pDS)
: CTWAIN_UI(pDS)
, m_pChildWnd(0, DeleteWnd)
, m_pDlg(0, DeleteWnd)
, m_pIndicator(0, DeleteWnd)
{
}
MFC_UI::~MFC_UI()
{
}
TW_INT16 MFC_UI::DisplayTWAINGUI(TW_USERINTERFACE Data, bool bSetup, bool bIndicators)
{
TW_INT16 ret = TWRC_SUCCESS;
TW_INT16 nRes = CTWAIN_UI::DisplayTWAINGUI(Data, bSetup, bIndicators);
if (nRes)
{
return nRes;
}
if (bSetup)
{
Data.ShowUI = 1;
}
if (Data.ShowUI == 0 && !bIndicators)
{
return ret;
}
if (Data.hParent)
{
m_pChildWnd = std::unique_ptr<CDialog, void(*)(CDialog*)>(new CDialog(), DeleteWnd);
m_pChildWnd->Create(IDD_DIALOGBACK, CWnd::FromHandle((HWND)Data.hParent));
long ll = GetWindowLong(m_pChildWnd->GetSafeHwnd(), GWL_STYLE);
SetWindowLong(m_pChildWnd->GetSafeHwnd(), GWL_STYLE, WS_CHILD | ll);
SetParent(m_pChildWnd->GetSafeHwnd(), (HWND)Data.hParent);
}
if (Data.ShowUI)
{
m_pDlg.reset(new TwainUIDlg(this, m_pChildWnd.get()));
m_pDlg->Create(IDD_DIALOG_TWAINUI, m_pChildWnd.get());
m_pDlg->SetDlgItemText(IDC_CONFIRM,bSetup ? _T("È·¶¨") : _T("ɨÃè"));
if (m_pDlg) {
m_pDlg->ShowWindow(SW_SHOWNORMAL);
}
else {
ret = TWRC_FAILURE;
}
}
return ret;
}
void MFC_UI::DestroyTWAINGUI()
{
m_pIndicator.reset();
m_pDlg.reset();
m_pChildWnd.reset();
CTWAIN_UI::DestroyTWAINGUI();
}
void MFC_UI::UpdateProgress(bool bShow, unsigned char ucProgress, unsigned int unPageNo, string strProgressTitle)
{
}
unsigned int MFC_UI::MyMessageBox(string strMessage, string strTitle, unsigned int unIconID)
{
if (m_pChildWnd != NULL)
{
return ::MessageBox(m_pChildWnd->m_hWnd, strMessage.c_str(), strTitle.c_str(), unIconID);
}
return ::MessageBox(NULL, strMessage.c_str(), strTitle.c_str(), unIconID);
}
bool MFC_UI::processEvent(pTW_EVENT _pEvent)
{
if (m_pDlg)
{
if (IsDialogMessage(m_pDlg->m_hWnd, (LPMSG)(((pTW_EVENT)_pEvent)->pEvent)))
{
m_pDlg->SendMessage(_pEvent->TWMessage);
return TRUE;
}
}
return FALSE;
}
void MFC_UI::ShowIndicators()
{
if (m_bIndicators) {
m_pIndicator.reset(new IndicatorDlg(this));
m_pIndicator->Create(IDD_DIALOG_INDICATOR,m_pDlg ? m_pDlg.get() : m_pChildWnd.get());
m_pIndicator->ShowWindow(SW_SHOWNORMAL);
}
}
void MFC_UI::DestroyIndicators()
{
m_pIndicator.reset();
}