// Configs.cpp : implementation file // #include "stdafx.h" #include "twnconfig.h" #include "Configs.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CConfigs dialog CConfigs::CConfigs(CWnd* pParent /*=NULL*/) : CDialog(CConfigs::IDD, pParent) { //{{AFX_DATA_INIT(CConfigs) //}}AFX_DATA_INIT m_pFileConfig= NULL; m_pMemConfig = NULL; m_pNtvConfig = NULL; m_nFileCount = 0; m_nMemCount = 0; m_nNtvCount = 0; m_pSelConfigs = NULL; m_nSelConfigsCount = 0; } CConfigs::~CConfigs() { if (m_pSelConfigs) GlobalFreePtr(m_pSelConfigs); } void CConfigs::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CConfigs) DDX_Control(pDX, IDC_LIST_MEM_MODE, m_lstMemConfig); DDX_Control(pDX, IDC_LIST_NATIVE_MODE, m_lstNativeConfig); DDX_Control(pDX, IDC_LIST_FILE_MODE, m_lstFileConfig); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CConfigs, CDialog) //{{AFX_MSG_MAP(CConfigs) ON_WM_DESTROY() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CConfigs message handlers BOOL CConfigs::OnInitDialog() { CDialog::OnInitDialog(); CString csText; CTwainConfigApp * pTheApp = (CTwainConfigApp *)AfxGetApp(); m_lstFileConfig.InsertColumn(0, _T("File Format"), LVCFMT_LEFT, 100, -1); m_lstFileConfig.InsertColumn(1, _T("BPP"), LVCFMT_LEFT, 50, -1); m_lstMemConfig.InsertColumn(0, _T("File Format"), LVCFMT_LEFT, 100, -1); m_lstMemConfig.InsertColumn(1, _T("Buffer Size"), LVCFMT_LEFT, 70, -1); m_lstMemConfig.InsertColumn(2, _T("BPP"), LVCFMT_LEFT, 50, -1); m_lstNativeConfig.InsertColumn(0, _T("File Format"), LVCFMT_LEFT, 100, -1); m_lstNativeConfig.InsertColumn(1, _T("BPP"), LVCFMT_LEFT, 50, -1); if (m_pFileConfig && m_nFileCount) { for(int i=0; iGetFormatName(&m_pFileConfig[i], csText); m_lstFileConfig.InsertItem(i, csText); csText.Format(_T("%d"), m_pFileConfig[i].nBitsPerPixel); m_lstFileConfig.SetItemText(i, 1, csText); m_lstFileConfig.SetItemData(i, (DWORD)&m_pFileConfig[i]); } } if (m_pMemConfig && m_nMemCount) { for(int i=0; iGetFormatName(&m_pMemConfig[i], csText); m_lstMemConfig.InsertItem(i, csText); csText.Format(_T("%d"), m_pMemConfig[i].ulBufferSize); m_lstMemConfig.SetItemText(i, 1, csText); csText.Format(_T("%d"), m_pMemConfig[i].nBitsPerPixel); m_lstMemConfig.SetItemText(i, 2, csText); m_lstMemConfig.SetItemData(i, (DWORD)&m_pMemConfig[i]); } } if (m_pNtvConfig && m_nNtvCount) { for(int i=0; iGetFormatName(&m_pNtvConfig[i], csText); m_lstNativeConfig.InsertItem(i, csText); csText.Format(_T("%d"), m_pNtvConfig[i].nBitsPerPixel); m_lstNativeConfig.SetItemText(i, 1, csText); m_lstNativeConfig.SetItemData(i, (DWORD)&m_pNtvConfig[i]); } } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CConfigs::OnDestroy() { if (m_pFileConfig) GlobalFreePtr(m_pFileConfig); if (m_pMemConfig) GlobalFreePtr(m_pMemConfig); if (m_pNtvConfig) GlobalFreePtr(m_pNtvConfig); CDialog::OnDestroy(); } void CConfigs::SetConfigs(pFASTCONFIG pConfig, L_INT nConfigCount, L_INT nTransferMode) { if (!pConfig || nConfigCount <=0) return; switch (nTransferMode) { case LTWAIN_FILE_MODE: m_pFileConfig = (pFASTCONFIG)GlobalAllocPtr(GHND, sizeof(FASTCONFIG) * nConfigCount); if (m_pFileConfig) { CopyConfigs(pConfig, nConfigCount, LTWAIN_FILE_MODE); m_nFileCount = nConfigCount; } break; case LTWAIN_BUFFER_MODE: if (!m_pMemConfig) m_pMemConfig = (pFASTCONFIG)GlobalAllocPtr(GHND, sizeof(FASTCONFIG) * nConfigCount); else m_pMemConfig = (pFASTCONFIG)GlobalReAllocPtr(m_pMemConfig, sizeof(FASTCONFIG) * (nConfigCount + m_nMemCount), GHND); if (m_pMemConfig) { CopyConfigs(pConfig, nConfigCount, LTWAIN_BUFFER_MODE); m_nMemCount = m_nMemCount + nConfigCount; } break; case LTWAIN_NATIVE_MODE: if (!m_pNtvConfig) m_pNtvConfig = (pFASTCONFIG)GlobalAllocPtr(GHND, sizeof(FASTCONFIG) * nConfigCount); else m_pNtvConfig = (pFASTCONFIG)GlobalReAllocPtr(m_pNtvConfig, sizeof(FASTCONFIG) * (nConfigCount + m_nNtvCount), GHND); if (m_pNtvConfig) { CopyConfigs(pConfig, nConfigCount, LTWAIN_NATIVE_MODE); m_nNtvCount = m_nNtvCount + nConfigCount; } break; } } void CConfigs::OnOK() { DWORD dwData; pFASTCONFIG pConfig; int nItem; int nNtvSelCount = m_lstNativeConfig.GetSelectedCount(); int nMemSelCount = m_lstMemConfig.GetSelectedCount(); int nFileSelCount = m_lstFileConfig.GetSelectedCount(); m_nSelConfigsCount = nNtvSelCount + nMemSelCount + nFileSelCount; if (!m_nSelConfigsCount) { MessageBox(_T("No selected configuration, please select some configurations before press OK"), _T("Select Manual Configuration")); return; } CDialog::OnOK(); m_pSelConfigs = (pFASTCONFIG)GlobalAllocPtr(GHND, sizeof(FASTCONFIG) * m_nSelConfigsCount); if (!m_pSelConfigs) { m_nSelConfigsCount = 0; return; } nItem = -1; for(int i=0; inFileFormat; m_pSelConfigs[i].ulBufferSize = pConfig->ulBufferSize; m_pSelConfigs[i].uTime = pConfig->uTime; m_pSelConfigs[i].nBitsPerPixel = pConfig->nBitsPerPixel; } nItem = -1; for(;inFileFormat; m_pSelConfigs[i].ulBufferSize = pConfig->ulBufferSize; m_pSelConfigs[i].uTime = pConfig->uTime; m_pSelConfigs[i].nBitsPerPixel = pConfig->nBitsPerPixel; } nItem = -1; for(;inFileFormat; m_pSelConfigs[i].ulBufferSize = pConfig->ulBufferSize; m_pSelConfigs[i].uTime = pConfig->uTime; m_pSelConfigs[i].nBitsPerPixel = pConfig->nBitsPerPixel; } } void CConfigs::CopyConfigs(pFASTCONFIG pConfigs, L_INT nConfigsCount, L_INT nTransferMode) { int i=0,j=0; switch (nTransferMode) { case LTWAIN_FILE_MODE: for (i=m_nFileCount; i