📄 faxdemo.cpp
字号:
#include <windows.h>
#include <commdlg.h>
#include <commctrl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include <wchar.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <mmsystem.h>
#include "..\\..\\..\\..\\inc\\tc08a32.h"
// add for test fax-Board
#include "faxapi32.h"
// end of add
#include "ModemAPI.h"
#include "resource.h"
#include "FaxCvt.h"
#define LINE 5
#define STATUS 70
#define LINK 140
//#define HOSTCODE 340
//#define DTMFCODE 365
#define FREE 800
#define PLAY 801
#define GETDTMF 802
#define INDEXPLAY 803
#define RECORDFILE 804
#define EXITRECORD 805
#define RECEIVE 1
#define SEND 2
#define MODEM 3
#define STANDARD_RESOLUTION 2
struct TRUNKSTRUCT
{
int Status;
int FaxCh;
int ConvCh;
char Code;
};
struct FAXSTRUCT
{
int Status;
int CurrPage;
int TotalPage;
char SendFaxName[32];
};
char VoicePath[100];
bool bHaveLoadDriver;
HINSTANCE hInst;
HINSTANCE hLib;
HWND hGWnd;
int TotalLine;
int TotalFaxLine;
TRUNKSTRUCT* pTrunk;
FAXSTRUCT* pFax;
extern HANDLE* pThreadHandle;
extern DWORD* pThreadID;
extern CONVERTSTRUCT* pConv;
int DispRegFlag = 0;
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam);
void WINAPI OutFax(int ChannelNo,char *Str);
void WINAPI OutStatus(int ChannelNo,char *Str);
void WINAPI OutLinkFax(int ChannelNo,char *Str);
void WINAPI FaxEvent(HWND hwnd);
bool WINAPI InitCard(HWND hWnd);
void WINAPI ExitCard();
void WINAPI GetVoicePath();
char Convert(int ch);
VOID CALLBACK TimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime);
int MyHangUpCheck(int Chnl);
int SendFlag = 0;
int PASCAL WinMain( HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdParam, int nCmdShow)
{
static char szAppName[] = "FaxDemo";
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
char strSys[200];
if (strnicmp ( lpszCmdParam, "s", 1 ) == 0) // disp single
DispRegFlag = 1;
if (strnicmp ( lpszCmdParam, "a", 1 ) == 0) // disp all
DispRegFlag = 2;
// Unused(lpszCmdParam);
if (!hPrevInstance)
{
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = (WNDPROC)WndProc;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = DLGWINDOWEXTRA;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (hInstance, "IDI_FAXDEMO");
wndclass.hCursor = LoadCursor (NULL, IDI_APPLICATION);
wndclass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
ATOM a=RegisterClass (&wndclass);
}
GetSystemDirectory(strSys,200);
strcat(strSys,"\\comctl32.dll");
hLib = LoadLibrary(strSys);
hInst = hInstance;
hwnd = CreateDialog(hInstance, "FAXDEMO", 0, NULL);
hGWnd=hwnd;
ShowWindow (hwnd, nCmdShow);
UpdateWindow(hwnd);
bHaveLoadDriver=InitCard(hwnd);
if(!bHaveLoadDriver) PostQuitMessage(0);
GetVoicePath();
FARPROC lpProc;
lpProc = MakeProcInstance((FARPROC)TimerProc, hInstance);
SetTimer(hwnd,ID_TIME,100,(TIMERPROC)lpProc);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam ;
}
VOID CALLBACK TimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
{
if(idEvent!=ID_TIME) return;
PUSH_PLAY();
FeedSigFunc();
FaxEvent(hwnd);
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam)
{
switch (message)
{
case WM_DESTROY :
KillTimer(hwnd,ID_TIME);
if(bHaveLoadDriver) ExitCard();
PostQuitMessage (0) ;
return 0 ;
break;
case WM_COMMAND:
if(LOWORD(wParam)==ID_OK)
{
KillTimer(hwnd,ID_TIME);
if(bHaveLoadDriver) ExitCard();
PostQuitMessage(0);
}
return 0;
break;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
bool WINAPI InitCard(HWND hWnd)
{
char sTmp1[128];
HINSTANCE hInstance;
hInstance = hInst;
if ( LoadDRV ( ) )
{
MessageBox ( hWnd, "Load driver FAIL", "Message", MB_OK );
return false;
}
TotalLine = CheckValidCh();
if ( EnableCard(TotalLine,1024*8) != (long)0)
{
FreeDRV();
MessageBox ( hWnd, "Enable Board FAIL", "Message", MB_OK );
return false;
}
SetBusyPara(700);
SetPackRate ( PACK_64KBPS );
if ( DJFax_DriverReady(2048) )
{
MessageBox ( hWnd, "Load Fax Driver Fail", "Message", MB_OK );
DisableCard();
FreeDRV();
return false;
}
TotalFaxLine = DJFax_GetTotalFaxChnl();
pTrunk=new TRUNKSTRUCT[TotalLine];
pFax=new FAXSTRUCT[TotalFaxLine];
for(int i = 0; i < TotalFaxLine; i++)
{
pFax[i].CurrPage = 0;
pFax[i].TotalPage = 0;
pFax[i].Status=0;
}
InitConvert();
for(i = 0; i < TotalLine; i++)
{
pTrunk[i].Status = 0;
pTrunk[i].FaxCh=-1;
pTrunk[i].ConvCh=-1;
}
static int ColumnWidth[60] = {50, 100, 50, 70, 150, 100, 50, 150};
LV_COLUMN lvc;
char dig[10];
lvc.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvc.iSubItem = 0;
LoadString(hInstance, IDS_CHANNEL_NO, sTmp1, 128);
lvc.pszText = sTmp1 ;
lvc.cx = ColumnWidth[0];
ListView_InsertColumn(GetDlgItem(hGWnd,IDC_STATELIST),0,&lvc);
ListView_InsertColumn(GetDlgItem(hGWnd,IDC_FAXLIST),0,&lvc);
lvc.iSubItem = 1;
LoadString(hInstance, IDS_FLOW, sTmp1, 128);
lvc.pszText = sTmp1 ;
lvc.cx = ColumnWidth[1];
ListView_InsertColumn(GetDlgItem(hGWnd,IDC_STATELIST),1,&lvc);
ListView_InsertColumn(GetDlgItem(hGWnd,IDC_FAXLIST),1,&lvc);
lvc.iSubItem = 2;
LoadString(hInstance, IDS_CONNECT, sTmp1, 128);
lvc.pszText = sTmp1 ;
lvc.cx = ColumnWidth[2];
ListView_InsertColumn(GetDlgItem(hGWnd,IDC_STATELIST),2,&lvc);
lvc.iSubItem=2;
lvc.pszText = "Reg1" ;
lvc.cx = ColumnWidth[3];
ListView_InsertColumn(GetDlgItem(hGWnd,IDC_FAXLIST),2,&lvc);
lvc.iSubItem=3;
lvc.pszText = "Reg2" ;
lvc.cx = ColumnWidth[4];
ListView_InsertColumn(GetDlgItem(hGWnd,IDC_FAXLIST),3,&lvc);
LV_ITEM lvi;
for(i = 0; i < TotalLine; i++)
{
lvi.mask = LVIF_TEXT;
lvi.iItem = i;
lvi.iSubItem = 0;
itoa( i, dig, 10 ) ;
lvi.pszText = dig;
ListView_InsertItem(GetDlgItem(hGWnd,IDC_STATELIST),&lvi);
OutStatus(i,"FREE");
}
for(i = 0; i < TotalFaxLine; i++)
{
lvi.mask = LVIF_TEXT;
lvi.iItem = i;
lvi.iSubItem = 0;
itoa( i, dig, 10 ) ;
lvi.pszText = dig;
ListView_InsertItem(GetDlgItem(hGWnd,IDC_FAXLIST),&lvi);
OutFax(i,"Free ...");
}
return true;
}
void WINAPI ExitCard()
{
ExitConvert();
DisableCard();
FreeDRV();
DJFax_DisableCard();
delete pTrunk;
delete pFax;
}
void WINAPI OutStatus(int ChannelNo,char *Str)
{
char tmpstr[128];
ListView_GetItemText(GetDlgItem(hGWnd,IDC_STATELIST), ChannelNo, 1, tmpstr, 128) ;
if ( strcmp(Str,tmpstr )!=0)
ListView_SetItemText(GetDlgItem(hGWnd,IDC_STATELIST), ChannelNo, 1, Str );
}
void WINAPI OutLinkFax(int ChannelNo,char *Str)
{
char tmpstr[128];
ListView_GetItemText(GetDlgItem(hGWnd,IDC_STATELIST), ChannelNo, 2, tmpstr, 128 ) ;
if ( strcmp(Str,tmpstr )!=0)
ListView_SetItemText(GetDlgItem(hGWnd,IDC_STATELIST), ChannelNo, 2, Str );
}
void WINAPI OutFax(int ChannelNo,char *Str)
{
char tmpstr[128];
ListView_GetItemText(GetDlgItem(hGWnd,IDC_FAXLIST), ChannelNo, 1, tmpstr, 128 ) ;
if ( strcmp(Str,tmpstr )!=0)
ListView_SetItemText(GetDlgItem(hGWnd,IDC_FAXLIST), ChannelNo, 1, Str );
}
// ---------------------- this is for good-fax, don't care --------------
void DispVal()
{
int i;
char TmpStr[60],State[60];
char s[10];
for ( i = 0; i < TotalFaxLine; i ++ )
{
sprintf ( TmpStr, "%d ", GF_GetVal(i,GF_TYPE_CONNECT_FLAG) );
sprintf ( s, "%d ", GF_GetVal(i,GF_TYPE_CHANNEL_FLAG) );
strcat(TmpStr,s);
if ( GF_GetVal(i,GF_TYPE_CARD_VERSION) == 1 )
sprintf ( s, "* " );
else
sprintf ( s, "- " );
strcat(TmpStr,s);
sprintf (s, "%d ", GF_GetVal(i, GF_TYPE_RESET_COUNT) );
strcat(TmpStr,s);
sprintf ( s, "%d ", GF_GetVal(i, GF_TYPE_CARD_FLAG) );
strcat(TmpStr,s);
ListView_GetItemText(GetDlgItem(hGWnd,IDC_FAXLIST), i, 2, State, 60 ) ;
if ( strcmp(State,TmpStr )!=0)
ListView_SetItemText(GetDlgItem(hGWnd,IDC_FAXLIST), i, 2, TmpStr );
}
}
void DispReg()
{
int i,j;
BYTE c;
char TmpStr[60],State[60],sss[10];
for ( i = 0; i < TotalFaxLine; i ++ )
{
strcpy ( TmpStr, "" );
for ( j = 0; j < 9; j ++ )
{
DJFax_GetValue(i,&c,j,1);
sprintf ( sss, "%02x ", c );
strcat ( TmpStr, sss );
}
ListView_GetItemText(GetDlgItem(hGWnd,IDC_FAXLIST), i, 3, State, 60 ) ;
if ( strcmp(State,TmpStr )!=0)
ListView_SetItemText(GetDlgItem(hGWnd,IDC_FAXLIST), i, 3, TmpStr );
}
}
void DispSomething()
{
SYSTEMTIME SysTime;
static WORD wOldSec=0;
WORD wSec;
GetSystemTime( &SysTime );
wSec = SysTime.wSecond;
if ( wOldSec != wSec ) {
wOldSec = wSec;
if ( DispRegFlag >= 1 )
DispVal();
if ( DispRegFlag >= 2 )
DispReg();
}
}
// ---------------------- end of good-fax ----------------------------
int MyHangUpCheck(int Chnl)
{
if(CheckChType(Chnl) == CHTYPE_TRUNK)
{
SetBusyPara(700);
if ( ( ReadCheckResult(Chnl,PLAY_CHECK) == R_BUSY ) && ( ReadBusyCount() >=2 ) )
return 1;
SetBusyPara(320);
if ( ( ReadCheckResult(Chnl,PLAY_CHECK) == R_BUSY ) && ( ReadBusyCount() >=2 ) )
return 1;
}
else
{
return !RingDetect(Chnl);
}
/*
WORD StartPoint, Count;
BYTE SigBuf[1024];
ReadSigBuf ( 0, &StartPoint, &Count, SigBuf );
*/
return 0;
}
// add for new modem buffer
char ModemBuf[128][256];
int NowBufPos[128];
void WINAPI FaxEvent(HWND hwnd)
{
int i,FaxChnl;;
char PStr[40];
int CheckReturn;
char FileName[13];
int Return;
HDC hDC;
static int F=0;
int ReadCount;
char ReadBuff[1024];
BYTE SetValue;
char filename[128];
int ConvID;
SetValue = 0x40;
hDC = GetDC(hwnd);
DispSomething();
for(i = 0; i < TotalLine; i++)
{
if ( pTrunk[i].Status !=0)
{ // check hang up
if ( MyHangUpCheck(i) == 1 )
pTrunk[i].Status = 650;
}
switch(pTrunk[i].Status)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -