twain2/hugaotwainds/MFC_UI.cpp

146 lines
2.7 KiB
C++
Raw Normal View History

#include "stdafx.h"
#include "MFC_UI.h"
#include "TwainUIDlg.h"
#include "IndicatorDlg.h"
#include "hugaotwainds.h"
#include "Resource.h"
#include "hugaotwainds.h"
extern ChugaotwaindsApp theApp;
MFC_UI::MFC_UI(CTWAINDS_FreeImage *pDS)
: CTWAIN_UI(pDS)
{
m_pDlg = NULL;
m_pChildWnd = NULL;
indicator=NULL;
indicatorCreated=false;
}
MFC_UI::~MFC_UI()
{
}
TW_INT16 MFC_UI::DisplayTWAINGUI(TW_USERINTERFACE Data, bool bSetup, bool bIndicators)
{
TW_INT16 nRes = CTWAIN_UI::DisplayTWAINGUI(Data, bSetup, bIndicators);
if (nRes)
{
return nRes;
}
if (bSetup)
{
Data.ShowUI = 1;
}
if (Data.ShowUI == 0 && !bIndicators)
{
return TWRC_SUCCESS;
}
if (Data.hParent)
{
CDialog* dlg = new CDialog();
dlg->Create(IDD_DIALOG_TWAINUI);
m_pChildWnd = dlg;
theApp.m_pMainWnd = m_pChildWnd;
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 (bIndicators)
{
indicator=new IndicatorDlg(this,Data.ShowUI?m_pDlg:m_pChildWnd);
showUI=Data.ShowUI;
}
if (Data.ShowUI)
{
m_pDlg = new TwainUIDlg(this, m_pChildWnd);
m_pDlg->Create(IDD_DIALOG_TWAINUI, m_pChildWnd);
if (!bSetup)
{
m_pDlg->SetDlgItemTextA(IDC_CONFIRM, _T("ɨ<EFBFBD><EFBFBD>"));
}
else
{
m_pDlg->SetDlgItemTextA(IDC_CONFIRM, _T("ȷ<EFBFBD><EFBFBD>"));
}
if (m_pDlg)
{
m_pDlg->ShowWindow(SW_SHOWNORMAL);
}
else
{
return TWRC_FAILURE;
}
}
return TWRC_SUCCESS;
}
void MFC_UI::DestroyTWAINGUI()
{
CTWAIN_UI::DestroyTWAINGUI();
if (indicator!=NULL)
{
indicator->DestroyWindow();
delete indicator;
indicator=NULL;
indicatorCreated=false;
}
if (m_pDlg!=NULL)
{
m_pDlg->DestroyWindow();
delete m_pDlg;
m_pDlg = NULL;
}
if (m_pChildWnd!=NULL)
{
m_pChildWnd->DestroyWindow();
delete m_pChildWnd;
m_pChildWnd = NULL;
}
}
void MFC_UI::UpdateProgress(bool bShow, unsigned char ucProgress, unsigned int unPageNo, string strProgressTitle)
{
if (indicator==NULL) return;
if (!indicatorCreated)
{
//indicator->Create(IDD_DIALOG_INDICATOR,showUI?m_pDlg:m_pChildWnd);
indicator->Create(IDD_DIALOG_INDICATOR,m_pChildWnd);
indicatorCreated=true;
}
indicator->ShowWindow(bShow?SW_SHOWNORMAL:SW_HIDE);
if (m_pDlg)
{
m_pDlg->EnableWindow(bShow?FALSE:TRUE);
}
}
unsigned int MFC_UI::MessageBox(string strMessage, string strTitle, unsigned int unIconID)
{
//QMessageBox msgBox(QMessageBox::NoIcon, strTitle.c_str(), strMessage.c_str());
return ::MessageBox(NULL, strMessage.c_str(), strTitle.c_str(), unIconID);
}
bool MFC_UI::processEvent(pTW_EVENT _pEvent)
{
if(m_pChildWnd)
{
if (IsDialogMessage(m_pChildWnd->m_hWnd, (LPMSG)(((pTW_EVENT)_pEvent)->pEvent)))
{
return TRUE;
}
}
return FALSE;
}