#include "stdafx.h"
#include "MdispMFC.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "MdispMFCDoc.h"
#include "MdispMFCView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BEGIN_MESSAGE_MAP(CMdispMFCApp, CWinApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
CMdispMFCApp::CMdispMFCApp()
{
m_isCurrentlyHookedOnErrors = false;
}
CMdispMFCApp theApp;
BOOL CMdispMFCApp::InitInstance()
{
LoadStdProfileSettings();
MappAllocDefault(M_DEFAULT,&m_MilApplication, &m_MilSystem, M_NULL, M_NULL, M_NULL);
MappHookFunction(M_DEFAULT, M_ERROR_CURRENT,DisplayErrorExt,this);
m_isCurrentlyHookedOnErrors = true;
MappControl(M_DEFAULT, M_ERROR,M_PRINT_DISABLE);
MsysInquire(m_MilSystem,M_DIGITIZER_NUM,&m_numberOfDigitizer);
if (m_numberOfDigitizer)
{
MdigAlloc(m_MilSystem,M_DEFAULT,MIL_TEXT("M_DEFAULT"),M_DEFAULT,&m_MilDigitizer);
MdigInquire(m_MilDigitizer,M_SIZE_X,&m_digitizerSizeX);
MdigInquire(m_MilDigitizer,M_SIZE_Y,&m_digitizerSizeY);
MdigInquire(m_MilDigitizer,M_SIZE_BAND,&m_digitizerNbBands);
}
m_isGrabStarted = FALSE;
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_MDISPTYPE,
RUNTIME_CLASS(CMdispMFCDoc),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CMdispMFCView));
AddDocTemplate(pDocTemplate);
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
if (!ProcessShellCommand(cmdInfo))
return FALSE;
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
return TRUE;
}
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
HICON m_hIcon;
virtual BOOL OnInitDialog();
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
m_hIcon = AfxGetApp()->LoadIcon(IDI_IMAGING);
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
return TRUE;
}
void CMdispMFCApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
int CMdispMFCApp::ExitInstance()
{
if(m_MilDigitizer)
MdigFree (m_MilDigitizer);
if(m_MilSystem)
MsysFree (m_MilSystem);
if(m_MilApplication)
{
MappControl(M_DEFAULT, M_ERROR,M_PRINT_ENABLE);
if(m_isCurrentlyHookedOnErrors)
{
MappHookFunction(M_DEFAULT, M_ERROR_CURRENT+M_UNHOOK,DisplayErrorExt,this);
m_isCurrentlyHookedOnErrors = false;
}
MappFree(m_MilApplication);
}
return CWinApp::ExitInstance();
}
MIL_INT MFTYPE DisplayErrorExt(MIL_INT HookType, MIL_ID EventId, void* UserDataPtr)
{
if(((CMdispMFCApp*) AfxGetApp())->DisplayError(HookType, EventId,
(CWinApp*) UserDataPtr) == M_NO)
{
MappHookFunction(M_DEFAULT, M_ERROR_CURRENT+M_UNHOOK,DisplayErrorExt,UserDataPtr);
((CMdispMFCApp*) AfxGetApp())->HookedOnErrors(false);
}
return M_NULL;
}
long MFTYPE CMdispMFCApp::DisplayError(MIL_INT HookType,
MIL_ID EventId,
void* UserDataPtr)
{
MIL_TEXT_CHAR ErrorMessageFunction[M_ERROR_MESSAGE_SIZE] = MIL_TEXT("");
MIL_TEXT_CHAR ErrorMessage[M_ERROR_MESSAGE_SIZE] = MIL_TEXT("");
MIL_TEXT_CHAR ErrorSubMessage1[M_ERROR_MESSAGE_SIZE] = MIL_TEXT("");
MIL_TEXT_CHAR ErrorSubMessage2[M_ERROR_MESSAGE_SIZE] = MIL_TEXT("");
MIL_TEXT_CHAR ErrorSubMessage3[M_ERROR_MESSAGE_SIZE] = MIL_TEXT("");
MIL_INT NbSubCode;
CString CErrorMessage;
MappGetHookInfo(EventId,M_MESSAGE+M_CURRENT_FCT,ErrorMessageFunction);
MappGetHookInfo(EventId,M_MESSAGE+M_CURRENT,ErrorMessage);
MappGetHookInfo(EventId,M_CURRENT_SUB_NB,&NbSubCode);
if (NbSubCode > 2)
MappGetHookInfo(EventId,M_MESSAGE+M_CURRENT_SUB_3,ErrorSubMessage3);
if (NbSubCode > 1)
MappGetHookInfo(EventId,M_MESSAGE+M_CURRENT_SUB_2,ErrorSubMessage2);
if (NbSubCode > 0)
MappGetHookInfo(EventId,M_MESSAGE+M_CURRENT_SUB_1,ErrorSubMessage1);
CErrorMessage = ErrorMessageFunction;
CErrorMessage = CErrorMessage + "\n";
CErrorMessage = CErrorMessage + ErrorMessage;
if(NbSubCode > 0)
{
CErrorMessage = CErrorMessage + "\n";
CErrorMessage = CErrorMessage + ErrorSubMessage1;
}
if(NbSubCode > 1)
{
CErrorMessage = CErrorMessage + "\n";
CErrorMessage = CErrorMessage + ErrorSubMessage2;
}
if(NbSubCode > 2)
{
CErrorMessage = CErrorMessage + "\n";
CErrorMessage = CErrorMessage + ErrorSubMessage3;
}
CErrorMessage = CErrorMessage + "\n\n";
CErrorMessage = CErrorMessage + "Do you want to continue error print?";
return (AfxMessageBox(CErrorMessage,MB_YESNO,0) == IDYES)?M_YES:M_NO;
}