// tst.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "Wgsmsx.h"
#include "gcommlib.h"
#include "resource.h"
#include "ComLin.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define DIALOG_TITLE SVR_NAME " Message File Indexing"

#define DllImport   __declspec(dllimport)

extern "C" DllImport VOID wgsMsgMove(CDialog* pDlg,CStatic* pSrc);
DllImport GBOOL wgsmulti(INT argc,CHAR **argv);
DllImport VOID wgsmsx(INT argc,
                      CHAR **argv,
                      CDialog* pDlg,
                      CStatic* pSrc,
                      CStatic* pDst,
                      CProgressCtrl* pSPrg,
                      CProgressCtrl* pMPrg,
                      VOID (*ef)(INT ec,CHAR *es));
VOID ehandler(INT ecode,CHAR *estr);

static CDialog *pDlg=NULL;

/////////////////////////////////////////////////////////////////////////////
// CTstApp

BEGIN_MESSAGE_MAP(CTstApp, CWinApp)
	//{{AFX_MSG_MAP(CTstApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTstApp construction

CTstApp::CTstApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CTstApp object

CTstApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CTstApp initialization

BOOL CTstApp::InitInstance()
{
     CStatic *pSrc;
     CStatic *pDst;
     CProgressCtrl *pSPrg;
     CProgressCtrl *pMPrg;
     CComLine myargs;

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

     ParseCommandLine((CCommandLineInfo &)myargs);
     wgsMsgMove((CDialog *)NULL,(CStatic *)NULL);
     pDlg=new CDialog;
     if (wgsmulti(myargs.m_argc,myargs.m_argv)) {
          pDlg->Create(IDD_MPROGRESS);
          pDlg->SetWindowText(DIALOG_TITLE);
          pSrc=(CStatic *)pDlg->GetDlgItem(IDC_PRCFIL);
          pDst=(CStatic *)pDlg->GetDlgItem(IDC_GENFIL);
          pSPrg=(CProgressCtrl *)pDlg->GetDlgItem(IDC_GENPROGS2);
          pMPrg=(CProgressCtrl *)pDlg->GetDlgItem(IDC_GENPROG);     
     }
     else {
          pDlg->Create(IDD_SPROGRESS);
          pDlg->SetWindowText(DIALOG_TITLE);
          pSrc=(CStatic *)pDlg->GetDlgItem(IDC_PRCFILS);
          pDst=(CStatic *)pDlg->GetDlgItem(IDC_GENFILS);
          pSPrg=(CProgressCtrl *)pDlg->GetDlgItem(IDC_GENPROGS);
          pMPrg=(CProgressCtrl *)NULL;
     }
     wgsmsx(myargs.m_argc,myargs.m_argv,pDlg,pSrc,pDst,pSPrg,pMPrg,ehandler);
     delete pDlg;
     pDlg=(CDialog *)NULL;

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}

VOID
ehandler(
INT ecode,
CHAR *estr)
{
     if (pDlg != NULL) {
          pDlg->ShowWindow(SW_HIDE);
          delete pDlg;
     }
     MessageBox(NULL,estr,"Message File Indexing Error",0);
     exit(1);
}