
/***************************************************************************
**
**    $Header:   D:/PICSLDV/SRC/LOG/PICINIT/COMMUNIC.CPP   1.12   09 Jan 1997 14:27:24   ZJRD  $
**
**    $Log:   D:/PICSLDV/SRC/LOG/PICINIT/COMMUNIC.CPP  $
** 
** Initial revision.
** 
****************************************************************************/

/////////////////////////////////////////////////////////////////////////////
//
//  File name:  COMMUNIC.CPP
//
//  Description:The implement file of the class CCommunicationDialog
//
//  Author:     Roger Zhang
//  Date:       10/06/95
//
//  Updated by: Frank
//  Date:       12/27/95
//
//  Modification:
//
//      1. 10/06/95, Ver 0.1d
//
//
//  Copyright (C) 1995 Microtek International. All rights reserved.
//
/////////////////////////////////////////////////////////////////////////////

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

#include "communic.h"
#include "init196.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

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

/////////////////////////////////////////////////////////////////////////////
// CCommunicationDialog dialog

CCommunicationDialog::CCommunicationDialog(CWnd* pParent /*=NULL*/)
    : CDialog(CCommunicationDialog::IDD, pParent)
{
    //{{AFX_DATA_INIT(CCommunicationDialog)
    m_nComType = 1;
	m_nComBaud = 3;
	m_bChecked = TRUE;
	//}}AFX_DATA_INIT
          
}

void CCommunicationDialog::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CCommunicationDialog)
	DDX_Control(pDX, IDC_COMM_BAUD1, m_Button_Baud1);
	DDX_Control(pDX, IDC_COMM_COM1, m_Button_Com1);
    DDX_Radio(pDX, IDC_COMM_COM1, m_nComType);
	DDX_Radio(pDX, IDC_COMM_BAUD1, m_nComBaud);
	DDX_Check(pDX, IDC_CHECK_AUTOBAUD, m_bChecked);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCommunicationDialog, CDialog)
    //{{AFX_MSG_MAP(CCommunicationDialog)
	ON_BN_CLICKED(IDC_CHECK_AUTOBAUD, OnCheckAutoBaud)
	ON_BN_CLICKED(ID_DETAIL, OnDetail)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CCommunicationDialog message handlers

BOOL CCommunicationDialog::OnInitDialog()
{
    CDialog::OnInitDialog();
    
    // TODO: Add extra initialization here
    CenterWindow();
    
    /*GetDlgItem(IDC_COMM_COM1)->EnableWindow(
    	((CWinSerialPICAgree*)(GetXviewAppJohn()->m_pTheCom))->SerialInfor[0]
    );                    
    GetDlgItem(IDC_COMM_COM2)->EnableWindow(
    	((CWinSerialPICAgree*)(GetXviewAppJohn()->m_pTheCom))->SerialInfor[1]
    );                    
    GetDlgItem(IDC_COMM_COM3)->EnableWindow(
    	((CWinSerialPICAgree*)(GetXviewAppJohn()->m_pTheCom))->SerialInfor[2]
    );                    
    GetDlgItem(IDC_COMM_COM4)->EnableWindow(
    	((CWinSerialPICAgree*)(GetXviewAppJohn()->m_pTheCom))->SerialInfor[3]
    );*/                    
    
    GetDlgItem(IDC_COMM_ST2)->EnableWindow(!m_bChecked);                    
    GetDlgItem(IDC_COMM_BAUD1)->EnableWindow(!m_bChecked);                    
    GetDlgItem(IDC_COMM_BAUD2)->EnableWindow(!m_bChecked);                    
    GetDlgItem(IDC_COMM_BAUD3)->EnableWindow(!m_bChecked);                    
    GetDlgItem(IDC_COMM_BAUD4)->EnableWindow(!m_bChecked);                    
    
    return TRUE;  // return TRUE  unless you set the focus to a control
}


void CCommunicationDialog::OnCheckAutoBaud()
{
	// TODO: Add your control notification handler code here
	m_bChecked = !m_bChecked;
	
    GetDlgItem(IDC_COMM_ST2)->EnableWindow(!m_bChecked);                    
    GetDlgItem(IDC_COMM_BAUD1)->EnableWindow(!m_bChecked);                    
    GetDlgItem(IDC_COMM_BAUD2)->EnableWindow(!m_bChecked);                    
    GetDlgItem(IDC_COMM_BAUD3)->EnableWindow(!m_bChecked);                    
    GetDlgItem(IDC_COMM_BAUD4)->EnableWindow(!m_bChecked);                    
}

void CCommunicationDialog::OnDetail()
{
	// TODO: Add your control notification handler code here
	
}

void CCommunicationDialog::OnCancel()
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

 
#ifdef __cplusplus
extern "C" {
#endif	// __cplusplus 

BOOL WINAPI OpenCommunicationDialog(BYTE& bComType,BYTE& bComBaud,BOOL& isAutoBaud) 
{
//	HINSTANCE hInstEXE = AfxGetResourceHandle();
//	AfxSetResourceHandle(::InitGetDLLHandle());	
	CCommunicationDialog dlg;
    dlg.m_nComType = bComType;
    dlg.m_nComBaud = bComBaud;
    if(dlg.DoModal() != IDOK) {
    	return FALSE;
    }	
    bComType = (BYTE)(dlg.m_nComType);
    isAutoBaud = dlg.m_bChecked;
    bComBaud = (BYTE)(dlg.m_nComBaud+1);	

//    AfxSetResourceHandle(hInstEXE);
    return TRUE;
 }                     

#ifdef __cplusplus
}
#endif




void CCommunicationDialog::OnOK()
{
	// TODO: Add extra validation here
		// TODO: Add your control notification handler code here
	GetDlgItem(IDC_COMM_ST2)->EnableWindow(TRUE);                    
    GetDlgItem(IDC_COMM_BAUD1)->EnableWindow(TRUE);                    
    GetDlgItem(IDC_COMM_BAUD2)->EnableWindow(TRUE);                    
    GetDlgItem(IDC_COMM_BAUD3)->EnableWindow(TRUE);                    
    GetDlgItem(IDC_COMM_BAUD4)->EnableWindow(TRUE);                    

    UpdateData();
    
	CDialog::OnOK();
}
