FAXSENDDlg.cpp
上传用户:zf1208
上传日期:2007-06-11
资源大小:291k
文件大小:13k
源码类别:

传真(Fax)编程

开发平台:

C/C++

  1. // FAXSENDDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "FAXSEND.h"
  5. #include "FAXSENDDlg.h"
  6. #include "tapifax.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CAboutDlg dialog used for App About
  14. CFAXSENDDlg *g_FaxDialog = NULL;
  15. class CAboutDlg : public CDialog
  16. {
  17. public:
  18. CAboutDlg();
  19. // Dialog Data
  20. //{{AFX_DATA(CAboutDlg)
  21. enum { IDD = IDD_ABOUTBOX };
  22. //}}AFX_DATA
  23. // ClassWizard generated virtual function overrides
  24. //{{AFX_VIRTUAL(CAboutDlg)
  25. protected:
  26. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  27. //}}AFX_VIRTUAL
  28. // Implementation
  29. protected:
  30. //{{AFX_MSG(CAboutDlg)
  31. //}}AFX_MSG
  32. DECLARE_MESSAGE_MAP()
  33. };
  34. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  35. {
  36. //{{AFX_DATA_INIT(CAboutDlg)
  37. //}}AFX_DATA_INIT
  38. }
  39. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  40. {
  41. CDialog::DoDataExchange(pDX);
  42. //{{AFX_DATA_MAP(CAboutDlg)
  43. //}}AFX_DATA_MAP
  44. }
  45. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  46. //{{AFX_MSG_MAP(CAboutDlg)
  47. // No message handlers
  48. //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CFAXSENDDlg dialog
  52. CFAXSENDDlg::CFAXSENDDlg(CWnd* pParent /*=NULL*/)
  53. : CDialog(CFAXSENDDlg::IDD, pParent)
  54. {
  55. //{{AFX_DATA_INIT(CFAXSENDDlg)
  56. m_CIS = _T("远程:");
  57. m_FaxFileName = _T("Google.tif");
  58. m_FaxNumber = _T("982755974"); 
  59. m_Speed = _T("");
  60. m_iSpeed = 0;
  61. m_bIs2D = TRUE;
  62. m_CreateHead = TRUE;
  63. m_iClass = 0;
  64. m_sIdentifi = _T("身份:");
  65. m_sIdentif = _T("0987654321");
  66. m_sTakeTime = _T("");
  67. m_nTimes = 0 ;
  68. m_bEcm = TRUE;
  69. m_sPage = _T("0");
  70. m_iVolume = 0;
  71. m_Remote = _T("");
  72. m_From = _T("NETFBI");
  73. m_Stat = _T("");
  74. m_Fax_data = _T("");
  75. m_iPort = 0;
  76. m_To = _T("MAGGIE");
  77. m_bEcmFlag = false;
  78. m_nResolution = 0;
  79. g_hFax = NULL ;
  80. //}}AFX_DATA_INIT
  81. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  82. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  83. }
  84. void CFAXSENDDlg::DoDataExchange(CDataExchange* pDX)
  85. {
  86. CDialog::DoDataExchange(pDX);
  87. //{{AFX_DATA_MAP(CFAXSENDDlg)
  88. DDX_Control(pDX, IDC_MODEM_LIST, m_ModemList);
  89. DDX_Text(pDX, IDC_STATIC_CIS, m_CIS);
  90. DDX_Text(pDX, IDC_EDIT1, m_FaxFileName);
  91. DDX_Text(pDX, IDC_EDIT2, m_FaxNumber);
  92. DDX_Text(pDX, IDC_STATIC_SPEED, m_Speed);
  93. DDX_CBIndex(pDX, IDC_MODEM_LIST2, m_iSpeed);
  94. DDX_Check(pDX, IDC_2DCOMPRESS, m_bIs2D);
  95. DDX_Check(pDX, IDC_CREATE_HEAD, m_CreateHead);
  96. DDX_CBIndex(pDX, IDC_MODEM_LIST3, m_iClass);
  97. DDX_Text(pDX, IDC_IDENTIFI, m_sIdentifi);
  98. DDX_Text(pDX, IDC_EDIT3, m_sIdentif);
  99. DDX_Text(pDX, IDC_TIME, m_sTakeTime);
  100. DDX_Check(pDX, IDC_2DCOMPRESS2, m_bEcm);
  101. DDX_Text(pDX, IDC_PAGE, m_sPage);
  102. DDX_Slider(pDX, ID_SLIDER1, m_iVolume);
  103. DDX_Text(pDX, IDC_STATIC_REMOTE, m_Remote);
  104. DDX_Text(pDX, IDC_EDIT5, m_From);
  105. DDX_Text(pDX, IDC_STATIC_OP, m_Stat);
  106. DDX_Text(pDX, IDC_STATIC_FAX_DATA, m_Fax_data);
  107. DDX_CBIndex(pDX, IDC_MODEM_LIST4, m_iPort);
  108. DDX_Text(pDX, IDC_EDIT4, m_To);
  109. DDX_Radio(pDX, IDC_RADIO1, m_nResolution);
  110. //}}AFX_DATA_MAP
  111. }
  112. BEGIN_MESSAGE_MAP(CFAXSENDDlg, CDialog)
  113. //{{AFX_MSG_MAP(CFAXSENDDlg)
  114. ON_WM_SYSCOMMAND()
  115. ON_WM_PAINT()
  116. ON_WM_QUERYDRAGICON()
  117. ON_BN_CLICKED(IDC_BUTTON1, OnSendFax)
  118. ON_BN_CLICKED(IDC_CANCEL_FAX, OnCancelFax)
  119. ON_WM_TIMER()
  120. ON_BN_CLICKED(IDC_CREATE_HEAD, OnCreateHead)
  121. ON_BN_CLICKED(IDC_STATIC_WWW, OnStaticWww)
  122. //}}AFX_MSG_MAP
  123. ON_MESSAGE(WM_SMARTFAX, OnSmartFax)
  124. END_MESSAGE_MAP()
  125. /////////////////////////////////////////////////////////////////////////////
  126. // CFAXSENDDlg message handlers
  127. BOOL CFAXSENDDlg::OnInitDialog()
  128. {
  129. CDialog::OnInitDialog();
  130. // Add "About..." menu item to system menu.
  131. // IDM_ABOUTBOX must be in the system command range.
  132. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  133. ASSERT(IDM_ABOUTBOX < 0xF000);
  134. CMenu* pSysMenu = GetSystemMenu(FALSE);
  135. if (pSysMenu != NULL)
  136. {
  137. CString strAboutMenu;
  138. strAboutMenu.LoadString(IDS_ABOUTBOX);
  139. if (!strAboutMenu.IsEmpty())
  140. {
  141. pSysMenu->AppendMenu(MF_SEPARATOR);
  142. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  143. }
  144. }
  145. // Set the icon for this dialog.  The framework does this automatically
  146. //  when the application's main window is not a dialog
  147. SetIcon(m_hIcon, TRUE); // Set big icon
  148. SetIcon(m_hIcon, FALSE); // Set small icon
  149. // TODO: Add extra initialization here
  150. CSliderCtrl *slider  = (CSliderCtrl *)GetDlgItem(ID_SLIDER1);
  151. slider->SetRange(0,3);
  152. m_iVolume = 1;
  153. this->UpdateData(false);
  154. GetModemDeviceList((unsigned long )&m_ModemList,FillComboBox);
  155. m_ModemList.SetCurSel(0);
  156. g_FaxDialog = this;
  157. return TRUE;  // return TRUE  unless you set the focus to a control
  158. }
  159. void CFAXSENDDlg::OnSysCommand(UINT nID, LPARAM lParam)
  160. {
  161. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  162. {
  163. CAboutDlg dlgAbout;
  164. dlgAbout.DoModal();
  165. }
  166. else
  167. {
  168. CDialog::OnSysCommand(nID, lParam);
  169. }
  170. }
  171. // If you add a minimize button to your dialog, you will need the code below
  172. //  to draw the icon.  For MFC applications using the document/view model,
  173. //  this is automatically done for you by the framework.
  174. void CFAXSENDDlg::OnPaint() 
  175. {
  176. if (IsIconic())
  177. {
  178. CPaintDC dc(this); // device context for painting
  179. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  180. // Center icon in client rectangle
  181. int cxIcon = GetSystemMetrics(SM_CXICON);
  182. int cyIcon = GetSystemMetrics(SM_CYICON);
  183. CRect rect;
  184. GetClientRect(&rect);
  185. int x = (rect.Width() - cxIcon + 1) / 2;
  186. int y = (rect.Height() - cyIcon + 1) / 2;
  187. // Draw the icon
  188. dc.DrawIcon(x, y, m_hIcon);
  189. }
  190. else
  191. {
  192. CDialog::OnPaint();
  193. }
  194. }
  195. // The system calls this to obtain the cursor to display while the user drags
  196. //  the minimized window.
  197. HCURSOR CFAXSENDDlg::OnQueryDragIcon()
  198. {
  199. return (HCURSOR) m_hIcon;
  200. }
  201. EFaxSpeed GetSelSpeed(int Index)
  202. {
  203. switch(Index)
  204. {
  205. case 0:
  206. return FS_1440;
  207. case 1:
  208. return FS_1200;
  209. case 2:
  210. return FS_9600;
  211. case 3:
  212. return FS_7200;
  213. case 4:
  214. return FS_4800;
  215. default:
  216. return FS_2400;
  217. }
  218. }
  219. EVolume GetFaxVolume(int Index)
  220. {
  221. switch(Index)
  222. {
  223. case 0:
  224. return VO_OFF;
  225. case 1:
  226. return VO_LOW;
  227. case 2:
  228. return VO_MIDDLE;
  229. default :
  230. return VO_HIGH;
  231. }
  232. }
  233. void CFAXSENDDlg::OnSendFax() 
  234. {
  235. // TODO: Add your control notification handler code here
  236. this->UpdateData(TRUE);
  237. if(m_iPort==0)  // From Tapi 
  238. {
  239. int nSel =  m_ModemList.GetCurSel();
  240. DWORD dwDevice = m_ModemList.GetItemData(nSel);
  241. if(dwDevice >=0 )
  242. {
  243. InitializeTAPI(dwDevice);
  244. InitFaxTapiCall(g_hLine,g_hCall);
  245. }
  246. }else   // From ComPort
  247. {
  248. ComPortSendFax();
  249. }
  250. }
  251. void CFAXSENDDlg::OnSmartFax(WPARAM wParam, LPARAM lParam)
  252. {
  253. static unsigned long faxdata = 0 ;
  254. this->UpdateData();
  255. switch(wParam)
  256. {
  257. case WM_FAXUSERCANCE:
  258. m_Stat =  "User Cancel Send fax...";
  259. //ShutdownTAPI();
  260. break;
  261. case WM_FAXMISSIONOUTOVER:
  262. {
  263. ShutdownTAPI();
  264. GetDlgItem(IDC_BUTTON1)->EnableWindow(true);
  265. GetDlgItem(IDOK)->EnableWindow(true);
  266. GetDlgItem(IDC_CANCEL_FAX)->EnableWindow(false);
  267. if (lParam==0)
  268. m_Stat =  "Send fax successful";
  269. else if(lParam==888)
  270. m_Stat =  "Send fax failed(USER CANCEL)";
  271. else 
  272. m_Stat =  "Send fax failed";
  273. KillTimer(100);   
  274. }
  275. break;
  276. case WM_FAXCHANGESTATE:
  277. {
  278. switch(lParam)
  279. {
  280. case FAXINIT:
  281. m_bEcmFlag = false ;
  282. m_nTimes = 0 ;
  283. SetTimer(100,1000, 0); 
  284. m_Remote="";
  285. faxdata = 0;
  286. m_Fax_data.Format("%dK",0);
  287. GetDlgItem(IDC_BUTTON1)->EnableWindow(false);
  288. GetDlgItem(IDOK)->EnableWindow(false);
  289. GetDlgItem(IDC_CANCEL_FAX)->EnableWindow(true);
  290. m_Stat =  "Init Device";
  291. this->UpdateData(false);
  292. break;
  293. case DIALFAX:
  294. m_Stat =  "Dialing...";
  295. break;
  296. case ANSWER:
  297. m_Stat =  "Answering...";
  298. break; 
  299. case NEGOTIATION:
  300. m_Stat =  "Negotiating...";
  301. break; 
  302. case TRAINING:
  303. m_Stat =  "Training....";
  304. break; 
  305. }
  306. }
  307. break; 
  308. case WM_FAXSETCIS:
  309. m_Remote.Format("%s",(char*)lParam );
  310. m_Remote.TrimLeft(" ");
  311. m_Remote.TrimRight(" ");
  312. break; 
  313. case WM_FAXSENDPAGEDATA:
  314. faxdata+=(long)lParam;
  315. m_Fax_data.Format("%dK",faxdata/1024);
  316. break;
  317. case WM_ACCEPTPAGE:
  318. m_Stat =  "Page accepted ...";
  319. break;
  320. case WM_REJECTPAGE:
  321. m_Stat =  "Page rejected ...";
  322. break;
  323. case WM_FAXSPEED:
  324. m_Speed.Format("%d%s",lParam,"00 bps");
  325. break;
  326. case WM_FAXPAGE:
  327. m_nPage = (int)lParam;
  328. m_sPage.Format("Page %d",m_nPage);
  329. break;
  330. case WM_FAXECM:
  331. m_bEcmFlag  =  lParam == 0 ? false : true ;
  332. break;
  333. case WM_FAXPROCESSPAGEDATA:
  334.      m_Stat =  "Sending page ";
  335. switch(lParam)
  336. {
  337. case D1DMR:
  338. if(m_bEcmFlag)
  339. m_Stat +=  "(ECM MH)...";
  340. else
  341. m_Stat += "(1DMH)...";
  342. break;
  343. case D2DMR:
  344. if(m_bEcmFlag)
  345. m_Stat +=  "(ECM 2DMR)...";
  346. else
  347. m_Stat += "(2DMR)...";
  348. break;
  349. case D2DMMR:
  350. if(m_bEcmFlag)
  351. m_Stat +=  "(ECM MMR)...";
  352. else
  353. m_Stat += "(2DMMR)...";
  354. break;
  355. }
  356.     break;
  357. default:
  358. ;
  359. }
  360. TRACE("OnSmartFax  wParam == %d ----- lParam == %d n",wParam,lParam);
  361. this->UpdateData(false);
  362. }
  363. void CFAXSENDDlg::OnCancelFax() 
  364. {
  365. AbortPort(&g_hFax);
  366. }
  367. void CFAXSENDDlg::OnTimer(UINT nIDEvent) 
  368. {
  369. // TODO: Add your message handler code here and/or call default
  370. if(nIDEvent == 100 )
  371. {
  372. CTimeSpan ts(0,0,0,m_nTimes++);
  373. m_sTakeTime.Format("%01d:%01d:%02d",ts.GetHours(),ts.GetMinutes(),ts.GetSeconds());
  374. this->UpdateData(false);
  375. }
  376. CDialog::OnTimer(nIDEvent);
  377. }
  378. void CFAXSENDDlg::FillComboBox(DWORD dwDevice, const char *sLineName, const char *ComPort, unsigned long lParam)
  379. {
  380. CComboBox *ModemList = (CComboBox *)lParam;
  381. int index = ModemList->AddString(sLineName);
  382. ModemList->SetItemData(index,dwDevice);
  383. }
  384. int CFAXSENDDlg::TapiSendFax()
  385. {
  386. this->UpdateData();
  387. DWORD CurrentProcess = GetPriorityClass(GetCurrentProcess());
  388. SFaxParam *Sender =(SFaxParam *) new SFaxParam; 
  389. Sender->hFax = &g_hFax;
  390. Sender->hCall = g_hCall;
  391. Sender->hLine = g_hLine;
  392. strcpy(Sender->FileName,GetFullPath(m_FaxFileName));
  393. strcpy(Sender->FaxNumber,m_FaxNumber) ;
  394. Sender->Hwnd = this->GetSafeHwnd();
  395. Sender->Msg = WM_SMARTFAX;
  396. Sender->nComPort = m_iPort;
  397. Sender->Speed = GetSelSpeed(m_iSpeed);
  398. Sender->Is2D = m_bIs2D == TRUE ? U2D_ENABLE : U2D_DISABLE ;
  399. Sender->CreateHead = m_CreateHead == TRUE ? CH_ENABLE : CH_DISABLE;
  400. Sender->Class = m_iClass == 0 ? CLASS_1 : CLASS_2  ;
  401. strcpy(Sender->Identifi,m_sIdentif);
  402. Sender->Ecm = m_bEcm == TRUE ? ECM_ENABLE : ECM_DISABLE ;
  403. Sender->Volume =GetFaxVolume(m_iVolume) ;
  404. strcpy(Sender->From,m_From);
  405. strcpy(Sender->To,m_To);
  406. Sender->Resolution = m_nResolution == 0 ?  RE_FINE : RE_STANDARD ;
  407. Sender->nStartPage = 1 ;
  408. TapiSmartSendFax(Sender);
  409. delete Sender;
  410. return 0;
  411. }
  412. int CFAXSENDDlg::ComPortSendFax()
  413. {
  414. this->GetDlgItem(IDC_BUTTON1)->EnableWindow(false);
  415. this->GetDlgItem(IDOK)->EnableWindow(false);
  416. this->UpdateData();
  417. SFaxParam *Sender =(SFaxParam *) new SFaxParam; 
  418. Sender->hFax = &g_hFax;
  419. strcpy(Sender->FileName,m_FaxFileName);
  420. strcpy(Sender->FaxNumber,m_FaxNumber) ;
  421. Sender->Hwnd = this->GetSafeHwnd();
  422. Sender->Msg = WM_SMARTFAX;
  423. Sender->nComPort = m_iPort;
  424.     
  425. Sender->Speed = GetSelSpeed(m_iSpeed);
  426. Sender->Is2D = m_bIs2D == TRUE ? U2D_ENABLE : U2D_DISABLE ;
  427. Sender->CreateHead = m_bEcm == TRUE ? CH_ENABLE : CH_DISABLE;
  428. Sender->Class = m_iClass == 0  ? CLASS_1 : CLASS_2  ;
  429. strcpy(Sender->Identifi,m_sIdentif);
  430. Sender->Ecm = m_bEcm == TRUE ? ECM_ENABLE : ECM_DISABLE ;
  431. Sender->Volume = GetFaxVolume(m_iVolume) ;
  432. strcpy(Sender->From,m_From);
  433. strcpy(Sender->To,m_To);
  434. Sender->nStartPage = 1 ;
  435. Sender->Resolution = m_nResolution == 0 ?  RE_FINE : RE_STANDARD ;
  436. int rc = SmartSendFax(Sender);
  437. delete Sender;
  438. return rc;
  439. }
  440. void CFAXSENDDlg::OnCreateHead() 
  441. {
  442. // TODO: Add your control notification handler code here
  443. BOOL fEnable ;
  444. this->UpdateData();
  445. fEnable = m_CreateHead ;
  446. GetDlgItem(IDC_EDIT5)->EnableWindow(fEnable);
  447. GetDlgItem(IDC_EDIT4)->EnableWindow(fEnable);
  448. GetDlgItem(IDC_STATIC_FROM)->EnableWindow(fEnable);
  449. GetDlgItem(IDC_STATIC_TO)->EnableWindow(fEnable);
  450. }
  451. CString CFAXSENDDlg::GetWorkPath()
  452. {
  453. char szPath[512];
  454. CString strTemp;
  455. int nPos;
  456. CString strWorkPath = _T( "" );
  457. GetModuleFileName( NULL , szPath , 512 );
  458. strTemp = szPath;
  459. nPos = strTemp.Find( '\' );
  460. while( nPos != -1 )
  461. {
  462. strWorkPath += strTemp.Left( nPos + 1 );
  463. strTemp = strTemp.Right( strlen( strTemp ) - nPos -1 );
  464. nPos = strTemp.Find( '\' );
  465. }
  466. return strWorkPath;
  467. }
  468. CString CFAXSENDDlg::GetFullPath(CString FileName)
  469. {
  470. int nPos = FileName.Find(':');
  471. if(nPos ==-1)
  472. {
  473. return GetWorkPath()+FileName;
  474. }
  475. return FileName;
  476. }
  477. void CFAXSENDDlg::OnStaticWww() 
  478. {
  479. // TODO: Add your control notification handler code here
  480. ShellExecute(NULL,"open","http://www.i-enet.com",NULL,NULL,SW_SHOWNORMAL);
  481. }