www.pudn.com > Fax_Polling.rar > AtrkFaxDlg.cpp


// AtrkFaxDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "AtrkFax.h" 
#include "AtrkFaxDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
 
//int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData); 
///////////////////////////////////////////////////////////////////////////// 
// CAtrkFaxDlg dialog 
 
CAtrkFaxDlg::CAtrkFaxDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CAtrkFaxDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CAtrkFaxDlg) 
	m_AutoFaxMode = 0; 
	m_MaxFaxSpeed = 1; 
	m_strRecordFile = _T(""); 
	m_strAppendSendFile = _T(""); 
	m_bMultiFax = FALSE; 
	m_bSetMixer = FALSE; 
	m_bHowFile = 0; 
	m_strSendPathFile = _T(""); 
	m_nStartPage = -1; 
	m_nEndPage = -1; 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
 
	m_LogFile	= NULL; 
	m_bLog		= FALSE; 
	m_nTabShow	= 0; 
	m_nSCTNumber= 0; 
} 
 
CAtrkFaxDlg::~CAtrkFaxDlg() 
{ 
	if(m_LogFile != NULL) 
		fclose(m_LogFile); 
} 
 
void CAtrkFaxDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	int m_OldMaxFaxSpeed = m_MaxFaxSpeed; 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CAtrkFaxDlg) 
	DDX_Control(pDX, IDC_LIST_BOX_SHOW, m_ListBox); 
	DDX_Control(pDX, IDC_COMBO_CurFaxCh, m_cmbFaxCh); 
	DDX_Control(pDX, IDC_COMBO_CurCh, m_cmbCurCh); 
	DDX_Control(pDX, IDC_TAB1, m_TabCtrl); 
	DDX_Control(pDX, IDC_TRK_CH_LIST, m_TrkChList); 
	DDX_Control(pDX, IDC_LIST_CH_INFO, m_FaxChList); 
	DDX_Radio(pDX, IDC_RADIO_MAX_SPEED1, m_MaxFaxSpeed); 
	DDX_Text(pDX, IDC_EDIT_RecordFile, m_strRecordFile); 
	DDX_Text(pDX, IDC_EDIT_AppendSendFile, m_strAppendSendFile); 
	DDX_Check(pDX, IDC_CHECK_Multi_Ch_Rec, m_bMultiFax); 
	DDX_Check(pDX, IDC_CHECK_SetRexMixer, m_bSetMixer); 
	DDX_Radio(pDX, IDC_SINGLE_FILE, m_bHowFile); 
	DDX_Text(pDX, IDC_EDIT_SEND_PATHFILE, m_strSendPathFile); 
	DDX_Text(pDX, IDC_EDIT_START_PAGE, m_nStartPage); 
	DDX_Text(pDX, IDC_EDIT_END_PAGE, m_nEndPage); 
	//}}AFX_DATA_MAP 
 
	if( m_OldMaxFaxSpeed != m_MaxFaxSpeed ) 
	{ 
		if(m_MaxFaxSpeed == 0)      SsmFaxSetMaxSpeed(4800); 
		else if(m_MaxFaxSpeed == 1) SsmFaxSetMaxSpeed(9600); 
		else if(m_MaxFaxSpeed == 2) SsmFaxSetMaxSpeed(14400); 
	} 
} 
 
BEGIN_MESSAGE_MAP(CAtrkFaxDlg, CDialog) 
	//{{AFX_MSG_MAP(CAtrkFaxDlg) 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_BN_CLICKED(IDC_RADIO_MAX_SPEED2, OnRadioMaxSpeed2) 
	ON_BN_CLICKED(IDC_RADIO_MAX_SPEED3, OnRadioMaxSpeed3) 
	ON_BN_CLICKED(IDC_RADIO_MAX_SPEED1, OnRadioMaxSpeed1) 
	ON_WM_DESTROY() 
	ON_WM_TIMER() 
	ON_BN_CLICKED(IDC_APPEND, OnAppend) 
	ON_BN_CLICKED(IDC_SELFN, OnSelfn) 
	ON_BN_CLICKED(IDC_BUTTON_STOP_FAX, OnButtonStopFax) 
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1) 
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2) 
	ON_BN_CLICKED(IDC_VIEWMANSENDFAXFILE, OnViewmansendfaxfile) 
	ON_BN_CLICKED(IDC_AUTOCALL, OnAutocall) 
	ON_WM_SHOWWINDOW() 
	ON_NOTIFY(TCN_SELCHANGING, IDC_TAB1, OnSelchangingTab1) 
	ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnSelchangeTab1) 
	ON_MESSAGE(AUTOSENDFAX, AutoSendFax) 
	ON_BN_CLICKED(IDC_BUTTON_AppendSend, OnBUTTONAppendSend) 
	ON_BN_CLICKED(IDC_BUTTON_APPEND, OnButtonAppend) 
	ON_BN_CLICKED(IDC_CHECK_Multi_Ch_Rec, OnCHECKMultiChRec) 
	ON_BN_CLICKED(IDC_CHECK_SetRexMixer, OnCHECKSetRexMixer) 
	ON_BN_CLICKED(IDC_SINGLE_FILE, OnSingleFile) 
	ON_BN_CLICKED(IDC_MULTI_FILE, OnMultiFile) 
	ON_BN_CLICKED(IDC_MULTI_FILE_SET_PAGE, OnMultiFileSetPage) 
	ON_BN_CLICKED(IDC_BTN_SHOW_FILE, OnBtnShowFile) 
	ON_BN_CLICKED(IDC_BUTTON_ADDIN, OnButtonAddin) 
	ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel) 
	ON_LBN_SELCHANGE(IDC_LIST_BOX_SHOW, OnSelchangeListBoxShow) 
	ON_LBN_DBLCLK(IDC_LIST_BOX_SHOW, OnDblclkListBoxShow) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CAtrkFaxDlg message handlers 
 
BOOL CAtrkFaxDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// Set the icon for this dialog.  The framework does this automatically 
	//  when the application's main window is not a dialog 
	SetIcon(m_hIcon, TRUE);			// Set big icon 
	SetIcon(m_hIcon, FALSE);		// Set small icon 
	 
	// TODO: Add extra initialization here 
 
	//+++start+++added by xxh for tab, 2003.12.10 
	TC_ITEM	tci; 
	tci.mask = TCIF_TEXT; 
	tci.pszText = "Fax Send/Receive"; 
	m_TabCtrl.InsertItem(0, &tci); 
	tci.pszText = "AutoCallout"; 
	m_TabCtrl.InsertItem(1, &tci); 
	tci.pszText = "AutoReceive"; 
	m_TabCtrl.InsertItem(2, &tci); 
	tci.pszText = "HeaderTool"; 
	m_TabCtrl.InsertItem(3,&tci); 
 
	m_firstDlg.Create(IDD_FIRST_DLG, m_TabCtrl.GetActiveWindow()); 
	m_secondDlg.Create(IDD_SECOND_DLG, m_TabCtrl.GetActiveWindow()); 
	m_thirdDlg.Create(IDD_THIRD_DLG, m_TabCtrl.GetActiveWindow()); 
	m_forthDlg.Create(IDD_FORTH_DLG, m_TabCtrl.GetActiveWindow());	 
	//m_secondDlg.GetCurrentPath(m_szCurPath); 
	//m_thirdDlg.GetCurrentPath(m_szCurPath); 
	//+++end+++added by xxh for tab, 2003.12.10 
 
	if( !myInitFaxBoard() ) 
	{ 
		PostQuitMessage(0); 
		return FALSE;	 
	} 
	 
	m_firstDlg.GetCurrentPath(m_szCurPath); 
	m_secondDlg.GetCurrentPath(m_szCurPath); 
	m_forthDlg.GetCurrectPath(m_szCurPath); 
	//m_szSendFaxFile[0] = '\0'; 
	//m_szManSendFaxFile[0] = '\0'; 
	InitATrunkListCtrl(); 
	InitChInfoList(); 
 
	char szLogFile[MAX_PATH]; 
	sprintf(szLogFile , "%s\\Fax.Log" , m_szCurPath); 
 
	m_LogFile = fopen(szLogFile , "a+"); 
 
	if(m_LogFile == NULL) 
	{ 
		AfxMessageBox(_T("fail to create log file")); 
		m_bLog = FALSE; 
	} 
	else 
		m_bLog = TRUE; 
 
	SetTimer(1,100,NULL); 
	m_ListBox.SetHorizontalExtent(1000); 
	//text 
/*	CString str1,str2; 
	int bb,dd; 
	str1.Format("d.tif"); 
	str1.TrimRight(); 
	str2 = str1.Right(5); 
	dd = str2.GetLength(); 
	bb = str2.Find('.'); 
	str2.Format("%d",3); 
	bb = str1.GetLength() - dd + bb; 
	str1.Insert(bb,str2[0]); 
*/	// 
 
 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
// If you add a minimize button to your dialog, you will need the code below 
//  to draw the icon.  For MFC applications using the document/view model, 
//  this is automatically done for you by the framework. 
 
void CAtrkFaxDlg::OnPaint()  
{ 
	if (IsIconic()) 
	{ 
		CPaintDC dc(this); // device context for painting 
 
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); 
 
		// Center icon in client rectangle 
		int cxIcon = GetSystemMetrics(SM_CXICON); 
		int cyIcon = GetSystemMetrics(SM_CYICON); 
		CRect rect; 
		GetClientRect(&rect); 
		int x = (rect.Width() - cxIcon + 1) / 2; 
		int y = (rect.Height() - cyIcon + 1) / 2; 
 
		// Draw the icon 
		dc.DrawIcon(x, y, m_hIcon); 
	} 
	else 
	{ 
		CDialog::OnPaint(); 
	} 
} 
 
// The system calls this to obtain the cursor to display while the user drags 
//  the minimized window. 
HCURSOR CAtrkFaxDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void CAtrkFaxDlg::OnRadioMaxSpeed2()  
{ 
	UpdateData(TRUE); 
} 
 
void CAtrkFaxDlg::OnRadioMaxSpeed3()  
{ 
	UpdateData(TRUE); 
} 
 
void CAtrkFaxDlg::OnRadioMaxSpeed1()  
{ 
	UpdateData(TRUE); 
} 
 
void CAtrkFaxDlg::OnAutoRcvPathButton()  
{ 
 
} 
 
 
 
void CAtrkFaxDlg::InitChInfoList() 
{ 
	static int ColumnWidth[10] = {25, 36, 250, 36, 60, 100, 140, 100}; 
	LV_COLUMN lvc; 
	lvc.mask =  LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; 
	 
	lvc.iSubItem = 0; 
	lvc.pszText = "ch" ; 
	lvc.cx = ColumnWidth[0]; 
	m_FaxChList.InsertColumn(0,&lvc); 
 
	lvc.iSubItem = 1; 
	lvc.pszText = "Mode"; 
	lvc.cx = ColumnWidth[1]; 
	m_FaxChList.InsertColumn(1,&lvc); 
 
	lvc.iSubItem = 2; 
	lvc.pszText = "ChannelState"; 
	lvc.cx = ColumnWidth[2]; 
	m_FaxChList.InsertColumn(2,&lvc); 
 
	lvc.iSubItem = 3; 
	lvc.pszText = "Pages"; 
	lvc.cx = ColumnWidth[3]; 
	m_FaxChList.InsertColumn(3,&lvc); 
 
	lvc.iSubItem = 4; 
	lvc.pszText = "GetID"; 
	lvc.cx = ColumnWidth[4]; 
	m_FaxChList.InsertColumn(4,&lvc); 
 
	lvc.iSubItem = 5; 
	lvc.pszText = "FileName"; 
	lvc.cx = ColumnWidth[5]; 
	m_FaxChList.InsertColumn(5,&lvc); 
 
	lvc.iSubItem = 6; 
	lvc.pszText = "ErrorMsg"; 
	lvc.cx = ColumnWidth[6]; 
	m_FaxChList.InsertColumn(6,&lvc); 
 
	lvc.iSubItem = 7; 
	lvc.pszText = "SsmCheckEnd"; 
	lvc.cx = ColumnWidth[7]; 
	m_FaxChList.InsertColumn(7,&lvc); 
 
	char dig[3]; 
	for(int i=0; i < m_nTotalCh; i++)	 
	{ 
		if( SsmGetChType(i) == FAX_CH 
			|| SsmGetChType(i) == SOFTFAX_CH) 
		{ 
			itoa( i, dig, 10 ); 
			m_FaxChList.InsertItem(i,dig); 
		} 
	} 
} 
 
void CAtrkFaxDlg::InitATrunkListCtrl() 
{ 
	static int ColumnWidth[10] = {40, 100, 100, 150, 250}; 
	LV_COLUMN lvc; 
	lvc.mask =  LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; 
	 
	lvc.iSubItem = 0; 
	lvc.pszText = "ch" ; 
	lvc.cx = ColumnWidth[0]; 
	m_TrkChList.InsertColumn(0,&lvc); 
 
	lvc.iSubItem = 1; 
	lvc.pszText = "ChannelState"; 
	lvc.cx = ColumnWidth[1]; 
	m_TrkChList.InsertColumn(1,&lvc); 
 
	lvc.iSubItem = 2; 
	lvc.pszText = "FaxState"; 
	lvc.cx = ColumnWidth[2]; 
	m_TrkChList.InsertColumn(2,&lvc); 
 
	lvc.iSubItem = 3; 
	lvc.pszText = "DTMF"; 
	lvc.cx = ColumnWidth[3]; 
	m_TrkChList.InsertColumn(3,&lvc); 
 
	lvc.iSubItem = 4; 
	lvc.pszText = "ErrorMsg"; 
	lvc.cx = ColumnWidth[4]; 
	m_TrkChList.InsertColumn(4,&lvc); 
 
	char dig[3]; 
	for(int i = 0; i < m_nTotalCh; i++) 
	{ 
		if( m_ATrkCh[i].EnCalled ) 
			m_TrkChList.InsertItem(i,_itoa(i, dig, 10)); 
	} 
} 
 
void CAtrkFaxDlg::myDrawSelect(int x, int y, Img_Block *pImg) 
{ 
	int x1=x+5, y1=y+5; 
 
	fBmp_PutLine(x1, y1, x1+7, y1+7, pImg); 
	fBmp_PutLine(x1+7, y1+7, x1+14, y1-5,pImg); 
 
	fBmp_PutLine(x1-1, y1, x1+7, y1+8, pImg); 
	fBmp_PutLine(x1+7, y1+8, x1+15, y1-5,pImg); 
} 
 
int CAtrkFaxDlg::myFindAnIdleCh() 
{ 
	CString str; 
	//int i; 
	switch(m_nTabShow) 
	{ 
	case 0: 
		m_firstDlg.m_cmbFaxCh.GetWindowText(str); 
		if(!str.IsEmpty()) 
		{ 
			return atoi(str); 
		} 
		else 
		for(int i=0;i200) 
			{ 
				m_ATrkCh[i].Step = TRK_HANGUP; 
			} 
			else 
			{ 
				if( SsmGet1stDtmfClr(i, &m_ATrkCh[i].dtmf) == 1 
					&&( m_ATrkCh[i].dtmf =='1' || m_ATrkCh[i].dtmf == '2' ) ) 
				{ 
					if( (ch = myFindAnIdleCh()) == -1 )		// no idle fax channel available 
					{ 
						m_ATrkCh[i].Step = TRK_HANGUP; 
					} 
					else 
					{ 
						SsmPlayIndexString( i ,"2" ); 
						m_ATrkCh[i].toFaxCh = ch; 
						m_FaxCh[ch].nTrunkch = i; 
						m_ATrkCh[i].Step = TRK_CHECK_PLAY_START; 
					} 
				} 
			} 
			break; 
 
		case TRK_CHECK_PLAY_START:	 
			if( m_ATrkCh[i].lineState == S_CALL_PENDING )			// remote user hangup detected 
			{ 
				SsmStopPlayIndex( i ); 
				m_ATrkCh[i].Step = TRK_HANGUP; 
			} 
			else if(  SsmCheckPlay( i ) )						//	end of play "step2.voc" 
			{ 
				ch = m_ATrkCh[i].toFaxCh; 
				SsmTalkWith( i, ch ); 
 
				if(m_ATrkCh[i].dtmf == '1') m_FaxCh[ch].Direction = C_SEND_FAX; 
				else                      m_FaxCh[ch].Direction = C_RECEIVE_FAX; 
				 
				m_FaxCh[ch].OffLine = 0; 
				m_FaxCh[ch].Go = 1;			//start receiving/sending a fax file 
				m_FaxCh[ch].Mode = 0;			//auto send/rcv 
				 
				m_ATrkCh[i].Step = TRK_CHECK_FAX_PROCESS; 
			} 
			break; 
		//---------------------------------------------- 
 
			 
		//----------------------------------------------- 
		// for manual send 
		case TRK_CHECK_AUTODIAL:						 
			switch( SsmChkAutoDial(i) ) 
			{      
			case DIAL_NO_DIALTONE  :  
				strcpy(m_ATrkCh[i].pChErrMsg , "No dial tone"); 
				WriteLog(m_ATrkCh[i].pChErrMsg); 
				m_ATrkCh[i].Step = TRK_HANGUP; 
				break; 
			case DIAL_BUSYTONE  : 
				strcpy(m_ATrkCh[i].pChErrMsg , "busy tone"); 
				WriteLog(m_ATrkCh[i].pChErrMsg); 
				m_ATrkCh[i].Step = TRK_HANGUP; 
				break; 
			case DIAL_ECHO_NOVOICE  : 
				strcpy(m_ATrkCh[i].pChErrMsg , "silence after ringback tone"); 
				WriteLog(m_ATrkCh[i].pChErrMsg); 
				m_ATrkCh[i].Step = TRK_HANGUP; 
				break; 
			case DIAL_NOVOICE   :   
				strcpy(m_ATrkCh[i].pChErrMsg , "silence after dialing"); 
				WriteLog(m_ATrkCh[i].pChErrMsg); 
				m_ATrkCh[i].Step = TRK_HANGUP; 
				break; 
			case DIAL_VOICEF1  : 
				strcpy(m_ATrkCh[i].pChErrMsg , "remote fax machine is in send state after pickup "); 
				WriteLog(m_ATrkCh[i].pChErrMsg); 
				m_ATrkCh[i].Step = TRK_HANGUP; 
				break; 
			case DIAL_NOANSWER : 
				strcpy(m_ATrkCh[i].pChErrMsg , "no answer"); 
				WriteLog(m_ATrkCh[i].pChErrMsg); 
				m_ATrkCh[i].Step = TRK_HANGUP; 
				break; 
				 
			case DIAL_VOICE : 
				m_ATrkCh[i].Fax_Answered = 0; 
				m_ATrkCh[i].Step = TRK_PLAY_MANUAL_HINT; 
				break; 
 
			case DIAL_VOICEF2 : 
				m_ATrkCh[i].Fax_Answered = 1; 
				m_ATrkCh[i].Step = TRK_MANUAL_FAX_START; 
				break; 
 
			default : 
				break; 
			} 
			break; 
 
		case TRK_PLAY_MANUAL_HINT:		 
			 
			SsmPlayIndexString( i , "2"); 
			m_ATrkCh[i].Step		= TRK_CHECK_MANUAL_PLAY_START; 
			break; 
 
		case TRK_CHECK_MANUAL_PLAY_START :	 
			if(  SsmCheckPlay(i) )						//	end of play "step2.voc" 
			{ 
				m_ATrkCh[i].Step		= TRK_MANUAL_FAX_START; 
			} 
			else 
			{ 
				switch( SsmGetToneAnalyzeResult(i) ) 
				{ 
				case 2 : 
					SsmStopPlayIndex( i ); 
					strcpy(m_ATrkCh[i].pChErrMsg , "busy tone"); 
					WriteLog(m_ATrkCh[i].pChErrMsg); 
					m_ATrkCh[i].Step = TRK_HANGUP; 
					break; 
				case 8 : 
					SsmStopPlayIndex(i); 
					SsmStopPlayIndex( i ); 
					m_ATrkCh[i].Fax_Answered = 1; 
					m_ATrkCh[i].Step		= TRK_MANUAL_FAX_START; 
					break; 
				default : 
					break; 
				} 
			} 
 
			break; 
		case TRK_MANUAL_FAX_START : 
			if( (ch = myFindAnIdleCh()) == -1 )		// no idle fax channel available 
			{ 
				m_ATrkCh[i].Step = TRK_HANGUP; 
			} 
			else 
			{ 
				SsmTalkWith( i , ch ); 
				SsmRecToFile(i,"aa.wav",-1,0,-1,-1,0); 
				m_ATrkCh[i].toFaxCh		= ch; 
				m_FaxCh[ch].Direction	= C_SEND_FAX; 
				m_FaxCh[ch].OffLine		= 0; 
				m_FaxCh[ch].nTrunkch = i; 
				m_FaxCh[ch].Go			= 1;			// start send a fax file 
				m_FaxCh[ch].Mode		= 1;			// manual send 
				m_FaxCh[ch].Fax_Answered = m_ATrkCh[i].Fax_Answered; 
				m_ATrkCh[i].Step		= TRK_CHECK_FAX_PROCESS; 
			} 
			break; 
		//----------------------------------------- 
			 
		case TRK_CHECK_FAX_PROCESS: 
			ch = m_ATrkCh[i].toFaxCh; 
			if(( m_ATrkCh[i].lineState == S_CALL_PENDING) || m_FaxCh[ch].Step == FAX_IDLE )	//off-line or end of sending/receiving fax 
			{ 
				SsmStopTalkWith( i, ch ); 
 
				if(m_ATrkCh[i].lineState == S_CALL_PENDING ) 
					m_FaxCh[ch].OffLine = 1;			// inform fax-channel disconnecting of line 
 
				m_ATrkCh[i].Step = TRK_HANGUP; 
				 
			} 
			break; 
 
		case TRK_HANGUP: 
			SsmHangup(i); 
			SsmStopRecToFile(i); 
			m_ATrkCh[i].Step = TRK_IDLE; 
			break; 
		} 
	} 
} 
					 
void CAtrkFaxDlg::myScanFaxCh() 
{ 
	CString strTemp,strName; 
	CFileFind	cff; 
	int n,m; 
	CString str; 
 
	for( int i=0; i< m_nTotalCh; i++ ) 
	{ 
		if( SsmGetChType(i) != FAX_CH 
			&& SsmGetChType(i) != SOFTFAX_CH)  
			continue; 
 
		switch(m_FaxCh[i].Step) 
		{ 
		case FAX_IDLE: 
			strcpy(m_FaxCh[i].Page,""); 
			strcpy(m_FaxCh[i].GetID,"");			 
			if( m_FaxCh[i].Go ) 
			{ 
				m_FaxCh[i].Go		= 0;				 
				m_FaxCh[i].Step	= FAX_START; 
			} 
			else  
				m_FaxCh[i].pChErrMsg[0] = '\0'; 
 
			break; 
 
		case FAX_START: 
 
			if(m_FaxCh[i].Direction == C_SEND_FAX)	// send a fax file 
			{ 
				SsmFaxSetSendMode( i, m_AutoFaxMode ); 
 
				if(m_FaxCh[i].Mode == 0)		//0 
				{ 
					//strcpy(szSendFaxFile , m_firstDlg.szSendPathFile); 
					m_FaxCh[i].bHaveStartPage = m_firstDlg.bHaveStartPage; 
					strcpy(m_FaxCh[i].szSendPathFile, m_firstDlg.szSendPathFile); 
					if(m_FaxCh[i].bHaveStartPage) 
					{ 
						m_FaxCh[i].nStartPage	= m_firstDlg.nStartPage; 
						m_FaxCh[i].nEndPage		= m_firstDlg.nEndPage; 
					} 
				} 
				else if(m_FaxCh[i].Mode == 1)	//1 
				{ 
					m_FaxCh[i].bHaveStartPage = m_secondDlg.m_bHaveStartPage; 
					if(m_FaxCh[i].bHaveStartPage) 
					{ 
						m_FaxCh[i].nStartPage	= m_secondDlg.m_nStartPage; 
						m_FaxCh[i].nEndPage		= m_secondDlg.m_nEndPage; 
					} 
				} 
				if(m_bHowFile == 0) 
				{ 
					if(m_FaxCh[i].bHaveStartPage) 
					{ 
						if( SsmFaxStartSendEx(i, m_FaxCh[i].szSendPathFile, m_FaxCh[i].nStartPage,m_FaxCh[i].nEndPage) == -1 )	//start sending fax file 
						{ 
							SsmGetLastErrMsg(m_FaxCh[i].pChErrMsg); 
							m_FaxCh[i].Step = FAX_IDLE; 
						} 
						else 
							m_FaxCh[i].Step = FAX_CHECK_END; 
					} 
					else 
					{ 
						if( SsmFaxStartSend(i, m_FaxCh[i].szSendPathFile) == -1 )	//start sending fax file 
						{ 
							SsmGetLastErrMsg(m_FaxCh[i].pChErrMsg); 
							m_FaxCh[i].Step = FAX_IDLE; 
						} 
						else					 
							m_FaxCh[i].Step = FAX_CHECK_END; 
					} 
				} 
				else if(m_bHowFile == 1) 
				{ 
					strcpy(m_szSendMultiPath, m_strRecordFile.GetBuffer(m_strRecordFile.GetLength())); 
					memset(m_szSendMultiFile, 0, sizeof(m_szSendMultiFile)); 
					for(int jj = 0; jj< m_nSCTNumber; jj++) 
					{ 
						if(m_szSendMultiFile[0] != 0) 
							strcat(m_szSendMultiFile, ";"); 
						strcat(m_szSendMultiFile, ffSCT[jj].szFileName); 
					} 
					if(SsmFaxSendMultiFile(i, m_szSendMultiPath, m_szSendMultiFile) == -1) 
					{ 
						SsmGetLastErrMsg(m_FaxCh[i].pChErrMsg); 
						m_FaxCh[i].Step = FAX_IDLE; 
					} 
					else					 
						m_FaxCh[i].Step = FAX_CHECK_END; 
				} 
				else if(m_bHowFile == 2) 
				{ 
					PFAX_FILE_SCT pSCT; 
					pSCT = ffSCT; 
					if(SsmFaxSendMultiFileEx(i, pSCT, m_nSCTNumber) == -1) 
					{ 
						SsmGetLastErrMsg(m_FaxCh[i].pChErrMsg); 
						m_FaxCh[i].Step = FAX_IDLE; 
					} 
					else					 
						m_FaxCh[i].Step = FAX_CHECK_END; 
				} 
 
 
			} 
			else 									// receive a fax file 
			{ 
				if(m_nTabShow == 0) 
				{ 
					strcpy(m_FaxCh[i].szRecPathFile,m_firstDlg.m_strRecPath.GetBuffer(m_firstDlg.m_strRecPath.GetLength())); 
					strcat(m_FaxCh[i].szRecPathFile,"\\"); 
					if(m_bMultiFax)	 
					{ 
						strTemp.Format("%s",m_firstDlg.m_strRecFile); 
						strTemp.TrimRight(); 
						str = strTemp.Right(5); 
						m	= str.GetLength(); 
						n	= str.Find('.'); 
						str.Format("%d",i); 
						n	= strTemp.GetLength() - m + n; 
						for(int jj=0;jj 0 || SsmFaxGetSendBytes(i) >0) 
					{ 
						WriteLog("fax send: failed operation at page phrase "); 
					//	m_FaxCh[i].Step = FAX_CHECK_STOP; 
					} 
					else 
					{ 
						if(m_FaxCh[i].Fax_Answered == 1) 
						{ 
							WriteLog("fas send: failed operation at handshaking phrase ");; 
						} 
						else if(m_FaxCh[i].Fax_Answered == 0) 
						{ 
							WriteLog("fax send: timeout because remote end did not press 'start' key "); 
						} 
					} 
					m_FaxCh[i].Step = FAX_CHECK_STOP; 
					break; 
				case 0 : 
					switch( SsmGetToneAnalyzeResult(m_FaxCh[i].nTrunkch) ) 
					{ 
					case 2 : 
						strcpy(m_FaxCh[i].pChErrMsg , "busy tone"); 
						SsmFaxStop(i); 
						m_FaxCh[i].Step = FAX_CHECK_STOP; 
						break; 
					case 8 : 
						m_FaxCh[i].Fax_Answered = 1; 
						break; 
					default : 
						break; 
					} 
					break; 
				case 3 : 
					switch( SsmGetToneAnalyzeResult(m_FaxCh[i].nTrunkch) ) 
					{ 
					case 2 : 
						strcpy(m_FaxCh[i].pChErrMsg , "OK"); 
						SsmFaxStop(i); 
						m_FaxCh[i].Step = FAX_CHECK_STOP; 
					default : 
						break; 
					} 
					break; 
				case -1 : 
					SsmGetLastErrMsg( m_FaxCh[i].pChErrMsg ); 
					m_FaxCh[i].Step = FAX_IDLE; 
					break; 
				} 
			} 
 
			break; 
 
		case FAX_CHECK_STOP:	 
			m_FaxCh[i].Step = FAX_IDLE; 
			break;		 
		} 
	} 
} 
 
void CAtrkFaxDlg::myUpdateChInfoList() 
{ 
	char newstat[250], oldstat[250]; 
	char statemsg[100]; 
	int nListIndex  = 0; 
 
	for(int i=0; iFree(pidl); 
				pMalloc->Release(); 
			} 
		}	 
 } 
 
void CAtrkFaxDlg::OnButton2()  
{ 
	CString str; 
	int		n; 
	UpdateData(); 
	m_cmbCurCh.GetWindowText(str); 
	if(str.IsEmpty()) 
	{ 
		MessageBox("Please set channel","Warning",MB_OK); 
		return; 
	} 
	n = atoi(str); 
	SsmHangup(n); 
 
} 
 
void CAtrkFaxDlg::OnViewmansendfaxfile()  
{ 
	 
} 
 
 
void CAtrkFaxDlg::OnAutocall()  
{ 
	 
} 
 
void CAtrkFaxDlg::WriteLog(char *szLog) 
{ 
	if(FALSE == m_bLog) 
		return; 
	 
	CString szWriteLog; 
	SYSTEMTIME st; 
	GetLocalTime(&st); 
 
	szWriteLog.Format("%04d-%02d-%02d %02d:%02d:%02d : %s\n" , st.wYear , st.wMonth , st.wDay , st.wHour , st.wMinute , st.wSecond , szLog); 
	fwrite((LPCTSTR)szWriteLog , szWriteLog.GetLength() , 1 , m_LogFile); 
	fflush(m_LogFile); 
} 
 
void CAtrkFaxDlg::OnShowWindow(BOOL bShow, UINT nStatus)  
{ 
	CDialog::OnShowWindow(bShow, nStatus); 
	 
	// TODO: Add your message handler code here 
	CRect tabRect, itemRect; 
	int nX, nY, nXc, nYc; 
 
	m_TabCtrl.GetClientRect(&tabRect); 
	m_TabCtrl.GetItemRect(0, &itemRect); 
 
	nX=itemRect.left+22+400 ; 
	nY=itemRect.bottom+90+200- 10; 
	nXc=tabRect.right-itemRect.left -30; 
	nYc=tabRect.bottom-nY+20+200+40; 
	 
	switch (m_nTabShow) 
	{ 
	case 0: 
		m_TabCtrl.SetCurSel(0); 
		m_firstDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW); 
		m_secondDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW); 
		m_thirdDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW); 
		m_forthDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW); 
		break; 
	case 1: 
		m_TabCtrl.SetCurSel(1); 
		m_firstDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW); 
		m_secondDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW); 
		m_thirdDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW); 
		m_forthDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW); 
		break; 
	case 2: 
		m_TabCtrl.SetCurSel(2); 
		m_firstDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW); 
		m_secondDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW); 
		m_thirdDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW); 
		m_forthDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW); 
		break; 
	case 3: 
		m_TabCtrl.SetCurSel(3); 
		m_firstDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW); 
		m_secondDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW); 
		m_thirdDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW); 
		m_forthDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW); 
	}	 
} 
 
void CAtrkFaxDlg::OnSelchangingTab1(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
 
	*pResult = 0; 
} 
 
void CAtrkFaxDlg::AutoSendFax()  
{ 
	int nTrunk,nFaxCh; 
	CString str; 
//	MessageBox("Ok1"); 
	m_secondDlg.m_cmbTrunkCh.GetWindowText(str); 
	nTrunk	= atoi(str); 
	str.ReleaseBuffer(-1); 
	m_secondDlg.m_cmbFaxCh.GetWindowText(str); 
	nFaxCh = atoi(str); 
	m_ATrkCh[nTrunk].toFaxCh = nFaxCh; 
	 
	sprintf(m_ATrkCh[nTrunk].pPhoNum,"%s", m_secondDlg.m_strCallNo); 
	sprintf(m_FaxCh[nFaxCh].szSendPathFile,"%s",m_secondDlg.szSendFile); 
	//append fax file 
 
	// 
	if((nFaxCh=SsmPickup(nTrunk)) == -1) 
	{ 
		MessageBox("SsmPickup Fail","Fail",MB_OK); 
		SsmHangup(nTrunk); 
	} 
	 
 
} 
 
void CAtrkFaxDlg::AutoSendFaxEx()  
{ 
	int nTrunk,nFaxCh; 
	CString str; 
//	MessageBox("Ok1"); 
	m_secondDlg.m_cmbTrunkCh.GetWindowText(str); 
	nTrunk	= atoi(str); 
	str.ReleaseBuffer(-1); 
	m_secondDlg.m_cmbFaxCh.GetWindowText(str); 
	nFaxCh = atoi(str); 
	m_ATrkCh[nTrunk].toFaxCh = nFaxCh; 
	 
	sprintf(m_ATrkCh[nTrunk].pPhoNum,"%s", m_secondDlg.m_strCallNo); 
	sprintf(m_FaxCh[nFaxCh].szSendPathFile,"%s",m_secondDlg.szSendFile); 
	//append fax file 
 
	// 
	if((nFaxCh=SsmPickup(nTrunk)) == -1) 
	{ 
		MessageBox("SsmPickup Fail","Fail",MB_OK); 
		SsmHangup(nTrunk); 
	} 
	 
 
} 
 
void CAtrkFaxDlg::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	// TODO: Add your control notification handler code here 
	int n = m_TabCtrl.GetCurSel(); 
  
	switch(n) 
	{ 
	case 0: 
		m_nTabShow = 0; 
		m_firstDlg.ShowWindow(SW_SHOW); 
		m_secondDlg.ShowWindow(SW_HIDE); 
		m_thirdDlg.ShowWindow(SW_HIDE); 
		m_forthDlg.ShowWindow(SW_HIDE); 
		break; 
	case 1: 
		m_nTabShow = 1; 
		m_firstDlg.ShowWindow(SW_HIDE); 
		m_secondDlg.ShowWindow(SW_SHOW); 
		m_thirdDlg.ShowWindow(FALSE); 
		m_forthDlg.ShowWindow(SW_HIDE); 
		break; 
	case 2: 
		m_nTabShow = 2; 
		m_firstDlg.ShowWindow(0); 
		m_secondDlg.ShowWindow(0); 
		m_thirdDlg.ShowWindow(1); 
		m_forthDlg.ShowWindow(SW_HIDE); 
		break; 
	case 3: 
		m_nTabShow = 3; 
		m_firstDlg.ShowWindow(0); 
		m_secondDlg.ShowWindow(0); 
		m_thirdDlg.ShowWindow(0); 
		m_forthDlg.ShowWindow(1); 
 
		break; 
	}	 
	*pResult = 0; 
} 
 
void CAtrkFaxDlg::OnBUTTONAppendSend()  
{ 
{ 
	CFileDialog cf(1, NULL, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, "Fax File(*.tif)|*.tif|Tif File(*.fax)|*.fax|Tiff File(*.tiff)|*.tiff|All File(*.*)|*.*|",NULL); 
	char path[MAX_PATH]; 
	strcpy(path, m_szCurPath); 
	cf.m_ofn.lpstrInitialDir = path; 
 
	if(cf.DoModal() == IDOK) 
	{ 
		//strcpy(m_strAppendFile.GetBuffer(MAX_PATH), cf.GetFileName()); 
		strcpy(m_strAppendSendFile.GetBuffer(MAX_PATH), cf.GetPathName()); 
		UpdateData(FALSE); 
		m_strAppendSendFile.ReleaseBuffer(-1); 
	} 
}	 
} 
 
void CAtrkFaxDlg::OnButtonAppend()  
{ 
	CString str; 
	int n,m; 
	m_cmbFaxCh.GetWindowText(str); 
	if(str.IsEmpty()) 
	{ 
		MessageBox("Set fax channel","Warning",MB_OK); 
	} 
	else 
		n = atoi(str); 
 
	m = SsmFaxAppendSend(n, m_strAppendSendFile.GetBuffer(m_strAppendSendFile.GetLength())); 
	if(m == -1) 
	{ 
		str.Format("Channel %d fail to append",n); 
		MessageBox(str,"Warning",MB_OK); 
	} 
	else 
	{ 
		str.Format("Channel %d succeed appending",n); 
		MessageBox(str,"Successful",MB_OK); 
	} 
} 
void CAtrkFaxDlg::OnCHECKMultiChRec()  
{ 
	// TODO: Add your control notification handler code here 
	UpdateData();	 
} 
 
void CAtrkFaxDlg::OnCHECKSetRexMixer()  
{ 
	CString str; 
	int n; 
	UpdateData(); 
	m_cmbCurCh.GetWindowText(str); 
	if(str.IsEmpty()) 
	{ 
		MessageBox("Please set channel Id","Warning",MB_OK); 
		return ; 
	} 
	n = atoi(str); 
	n = SsmSetRecMixer(n, m_bSetMixer,0); 
	if(n ==-1) 
		MessageBox("SsmSetRecMixer Error","Error",MB_OK); 
} 
 
void CAtrkFaxDlg::OnSingleFile()  
{ 
	// TODO: Add your control notification handler code here 
	UpdateData(); 
	CWnd * p = GetDlgItem(IDC_EDIT_RecordFile); 
	p->ShowWindow(0); 
	p = GetDlgItem(IDC_BUTTON1); 
	p->ShowWindow(0); 
	p = GetDlgItem(IDC_BUTTON_ADDIN); 
 
	p = GetDlgItem(IDC_EDIT_START_PAGE); 
	p->EnableWindow(1); 
	p = GetDlgItem(IDC_EDIT_END_PAGE); 
	p->EnableWindow(1); 
} 
 
void CAtrkFaxDlg::OnMultiFile()  
{ 
	// TODO: Add your control notification handler code here 
	UpdateData(); 
	CWnd * p = GetDlgItem(IDC_EDIT_RecordFile); 
	p->ShowWindow(1); 
	p = GetDlgItem(IDC_BUTTON1); 
	p->ShowWindow(1); 
	p = GetDlgItem(IDC_EDIT_START_PAGE); 
	p->EnableWindow(0); 
	p = GetDlgItem(IDC_EDIT_END_PAGE); 
	p->EnableWindow(0); 
} 
 
void CAtrkFaxDlg::OnMultiFileSetPage()  
{ 
	// TODO: Add your control notification handler code here 
	UpdateData(); 
	CWnd * p = GetDlgItem(IDC_EDIT_RecordFile); 
	p->ShowWindow(0); 
	p = GetDlgItem(IDC_BUTTON1); 
	p->ShowWindow(0); 
	p = GetDlgItem(IDC_EDIT_START_PAGE); 
	p->EnableWindow(1); 
	p = GetDlgItem(IDC_EDIT_END_PAGE); 
	p->EnableWindow(1); 
} 
 
void CAtrkFaxDlg::OnBtnShowFile()  
{ 
	if(m_bHowFile == 0 || m_bHowFile == 2) 
	{ 
		CFileDialog cf(1, NULL, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, "Fax File(*.tif)|*.tif|Tif File(*.fax)|*.fax|Tiff File(*.tiff)|*.tiff|All File(*.*)|*.*|",NULL); 
		char path[MAX_PATH]; 
		strcpy(path, m_szCurPath); 
		cf.m_ofn.lpstrInitialDir = path; 
 
		if(cf.DoModal() == IDOK) 
		{ 
			strcpy(m_strSendPathFile.GetBuffer(MAX_PATH), cf.GetPathName()); 
			//strcpy(szSendPathFile, cf.GetPathName()); 
			UpdateData(FALSE); 
			m_strSendPathFile.ReleaseBuffer(-1); 
		}	 
 
	} 
	else if(m_bHowFile == 1) 
	{ 
		CFileDialog cf(1, NULL, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, "Fax File(*.tif)|*.tif|Tif File(*.fax)|*.fax|Tiff File(*.tiff)|*.tiff|All File(*.*)|*.*|",NULL); 
		char path[MAX_PATH]; 
		strcpy(path, m_szCurPath); 
		cf.m_ofn.lpstrInitialDir = path; 
 
		if(cf.DoModal() == IDOK) 
		{ 
			//strcpy(m_strSendPathFile.GetBuffer(MAX_PATH), cf.GetPathName()); 
			strcpy(m_strSendPathFile.GetBuffer(MAX_PATH), cf.GetFileName()); 
			UpdateData(FALSE); 
			m_strSendPathFile.ReleaseBuffer(-1); 
		}	 
	} 
 
 
 
	 
} 
 
void CAtrkFaxDlg::OnButtonAddin()  
{	 
	if(m_strSendPathFile.IsEmpty())	return; 
	UpdateData(); 
	int n = m_ListBox.InsertString(-1, m_strSendPathFile); 
	strcpy(ffSCT[m_nSCTNumber].szFileName, m_strSendPathFile); 
	ffSCT[m_nSCTNumber].nStartPage  = m_nStartPage; 
	ffSCT[m_nSCTNumber].nEndPage	= m_nEndPage; 
	if(++m_nSCTNumber >= 50) 
		m_nSCTNumber = 0; 
	m_ListBox.SetCurSel(n); 
} 
 
void CAtrkFaxDlg::OnButtonDel()  
{ 
	// TODO: Add your control notification handler code here 
	int m = m_ListBox.GetCurSel(); 
	if(m == -1)	return ; 
	CString str; 
	m_ListBox.GetText(m,str); 
	m_ListBox.DeleteString(m); 
	for(int n = 0; n < m_nSCTNumber; n++) 
	{ 
		if(strcmp(ffSCT[n].szFileName, str) == 0 && m == n) 
		{ 
			for(n = n + 1; n < m_nSCTNumber; n++) 
			{ 
				memcpy(&ffSCT[n-1], &ffSCT[n], sizeof(FAX_FILE_SCT)); 
			} 
			m_nSCTNumber--; 
			if(m >= m_nSCTNumber)	m = 0; 
			m_ListBox.SetCurSel(m); 
			OnSelchangeListBoxShow(); 
			break; 
		} 
	} 
} 
 
void CAtrkFaxDlg::OnSelchangeListBoxShow()  
{ 
	int n = m_ListBox.GetCurSel(); 
	if(n == -1)	return; 
	CString str; 
	m_ListBox.GetText(n, str); 
	for(int i = 0; i< m_nSCTNumber; i++) 
	{ 
		if(strcmp(ffSCT[i].szFileName, str) == 0 && i == n) 
		{ 
			m_nStartPage = ffSCT[i].nStartPage; 
			m_nEndPage   = ffSCT[i].nEndPage; 
			UpdateData(FALSE); 
			break; 
		} 
	} 
} 
 
void CAtrkFaxDlg::OnDblclkListBoxShow()  
{ 
	// TODO: Add your control notification handler code here 
	int n = m_ListBox.GetCurSel(); 
	if(n == -1)	return; 
	CString str; 
	m_ListBox.GetText(n, str); 
	for(int i = 0; i< m_nSCTNumber; i++) 
	{ 
		if(strcmp(ffSCT[i].szFileName, str) == 0 && i == n) 
		{ 
			m_nStartPage = ffSCT[i].nStartPage; 
			m_nEndPage   = ffSCT[i].nEndPage; 
			UpdateData(FALSE); 
			break; 
		} 
	}	 
}