/***************************************************************************
**
**    $Header:   D:/EPSLDV1/SRC/LOG/MAKETAB/MAINTAB.CPP   1.6   20 Jun 1996 09:34:06   ZJRD  $
**
**    $Log:   D:/EPSLDV1/SRC/LOG/MAKETAB/MAINTAB.CPP  $
** 
**    Rev 1.6   20 Jun 1996 09:34:06   ZJRD
** EasyPack/SLD Version 1.20a
** 
**    Rev 1.4   10 Jun 1996 10:28:34   ZJRD
** EasyPack/SLD Version 1.20
** 
**    Rev 1.2   29 May 1996 09:42:38   ZJRD
** No change.
** 
**    Rev 1.1   16 May 1996 09:11:54   ZJRD
** No change.
** 
**    Rev 1.0   10 May 1996 09:24:04   ZJRD
** Initial revision.
** 
****************************************************************************/

#include "stdafx.h"
#include "resource.h"

#include "maintab.h" 
int MakeTable(void);
int test_read(void);



/////////////////////////////////////////////////////////////////////////////

// theApp:
// Just creating this application object runs the whole application.
//
CTheApp NEAR theApp;

/////////////////////////////////////////////////////////////////////////////

// CMainWindow constructor:
// Create the window with the appropriate style, size, menu, etc.
//
CMainWindow::CMainWindow()
{
    nFlag = 0;
    Create( NULL, "Make Command Table",
        WS_OVERLAPPEDWINDOW, rectDefault, NULL, "MainMenu" );
}

// OnPaint:
// This routine draws the string "Hello, Windows!" in the center of the
// client area.  It is called whenever Windows sends a WM_PAINT message.
// Note that creating a CPaintDC automatically does a BeginPaint and
// an EndPaint call is done when it is destroyed at the end of this
// function.  CPaintDC's constructor needs the window (this).
//
void CMainWindow::OnPaint()
{
    CString s;
    if (nFlag == 0)
        s = "Select table item in file menu to make table.";
    else if(nFlag == 1)
        s= "Table have be made sucessfully!";
    else
        s= "File not find. could not make table";
        
    CPaintDC dc( this );
    CRect rect;

    GetClientRect( rect );
    dc.SetTextAlign( TA_BASELINE | TA_CENTER );
    dc.SetTextColor( ::GetSysColor( COLOR_WINDOWTEXT ) );
    dc.SetBkMode(TRANSPARENT);
    dc.TextOut( ( rect.right / 2 ), ( rect.bottom / 2 ),
                s, s.GetLength() );
}

void CMainWindow::OnTable()
{
    static int k=0;
    if(k==0){
        nFlag = MakeTable();
        Invalidate(TRUE);
        k++;
    }
    else test_read();
}                                 

void CMainWindow::OnExit()
{
    PostMessage(WM_CLOSE);
}

//
BEGIN_MESSAGE_MAP( CMainWindow, CFrameWnd )
    //{{AFX_MSG_MAP( CMainWindow )
    ON_WM_PAINT()
    ON_COMMAND( IDM_TABLE, OnTable )
    ON_COMMAND( IDM_EXIT, OnExit )
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTheApp

// InitInstance:
// When any CTheApp object is created, this member function is automatically
// called.  Any data may be set up at this point.
//
// Also, the main window of the application should be created and shown here.
// Return TRUE if the initialization is successful.
//
BOOL CTheApp::InitInstance()
{
    TRACE( "HELLO \n" );

    SetDialogBkColor();     // hook gray dialogs (was default in MFC V1)

    m_pMainWnd = new CMainWindow();
    m_pMainWnd->ShowWindow( m_nCmdShow );
    m_pMainWnd->UpdateWindow();

    return TRUE;
}
