⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fdemo.c

📁 传真示例
💻 C
📖 第 1 页 / 共 5 页
字号:

 /********************************************************************
 *                                                                   *
 *   FFFFFFF  DDDDDD   EEEEEEE  M     M   OOOOO             CCCCC    *
 *   FF       DD   DD  EE       MM   MM  OO   OO           CC   CC   *
 *   FF       DD   DD  EE       MMM MMM  OO   OO           CC        *
 *   FFFFF    DD   DD  EEEEE    M MMM M  OO   OO           CC        *
 *   FF       DD   DD  EE       M  M  M  OO   OO           CC        *
 *   FF       DD   DD  EE       M     M  OO   OO   ..      CC   CC   *
 *   FF       DDDDDD   EEEEEEE  M     M   OOOOO    ..       CCCCC    *
 *                                                                   *
 *********************************************************************
 * (C)opyright 1996, Dialogic Corp.                                  *
 ********************************************************************/

//#define __STDC__ 1
#define STRICT			
#include <windows.h>	// windows header files
#include <windowsx.h>
#include <commdlg.h>
#include <commctrl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <io.h>
#include <dlgs.h>		// for modifying common dialog 

#include "srllib.h"	// Dialogic header files	
#include "dxxxlib.h"
#include "faxlib.h"

#include "resource.h"
#include "fdemo.h"

/************************************************************
 * Global Data
 ************************************************************/

// WIN32 application data
char szAppName[] = "FDEMO";
char szFrame[] = "FdemoMdiFrame";
char szChild[] = "FdemoMdiChild";

HANDLE   hInst;         // instance handle for this execution
HWND     hwndFrame;     // handle of MDI frame window
HWND     hwndClient;    // handle of MDI client window
HANDLE   hAccelTable;

// data used by Send File Open Dialog
OPENFILENAME ofn;
CHAR szFile[MAXFILELEN] = "\0";
CHAR szFilter[] = "TIFF/F Files (*.TIF)\0*.TIF\0Text Files (*.TXT)\0*.TXT\0All Files (*.*)\0*.*\0";

SENDFILELIST SendFileList = {0};
LPSENDFILELIST lpSendFileList = &SendFileList;

// receive file path name
CHAR szRxPath[MAXFILELEN] = "\0";

// static data for combo boxes 
char *BaudRates[] =  {"14400", "12000", "9600", "7200", "4800", "2400"};
char *Coding[] =  {"MH", "MR", "MMR"};

// default ASCII settings
DF_ASCIIDATA dftasciidata = {110,DF_PAD,2,2,3,3,DF_SINGLESPACE,DF_FONT_0,8,DF_UNITS_IN10,0};

// data used by OpenDevice dialog 
char szNewDevName[MAXDEVNAMELEN];

// font information used by text out routine
int tmAveCharWidth;
int tmHeight;

// array of available fax boards, initialized by GetFaxBoards
// during startup
int FaxBoardCount = 0;
char FaxBoardArray[MAXFAXBOARDS][MAXDEVNAMELEN];

/************************************************************
 *        NAME: FrameOnCreate
 * DESCRIPTION: Main window creation, create MDI cient control window
 *              and init SRL to post events to FrameWndProc()
 ************************************************************/
BOOL FrameOnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
{
   CLIENTCREATESTRUCT ccs;
   HDC hdc;
   TEXTMETRIC tm;

   ZeroMemory(&ccs,sizeof(ccs));
   
   // Find window menu where children will be listed 
   ccs.hWindowMenu  = GetSubMenu (GetMenu(hwnd),WINDOWMENUOFS);
   ccs.idFirstChild = IDM_WINDOWCHILD;

   // Create the MDI client 
   hwndClient = CreateWindow ("mdiclient",
      NULL,
      WS_CHILD | WS_CLIPCHILDREN,
      CW_USEDEFAULT, CW_USEDEFAULT,
      CW_USEDEFAULT, CW_USEDEFAULT,
      hwnd,
      0,
      hInst,
      (LPSTR)&ccs);

   // display it
   ShowWindow (hwndClient,SW_SHOW);

   // get font characteristics and save them
   hdc = GetDC(hwnd);
   GetTextMetrics(hdc, &tm);
   ReleaseDC(hwnd, hdc);

   tmAveCharWidth = tm.tmAveCharWidth;
   tmHeight       = tm.tmHeight;

	// determine and init fax board array 
	if (GetFaxBoards() == 0) {
		return FALSE;
		}

   // enable SRL events to be sent to Frame window for processing
   sr_NotifyEvent(hwnd, WM_SRLNOTIFYEVENT, SR_NOTIFY_ON);
   return(TRUE);

}   

/************************************************************
 *        NAME: FrameOnCommand
 * DESCRIPTION: Handle WM_COMMAND menu processing
 *              Process menu selections 
 ************************************************************/
void FrameOnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
   HWND hwndChild;

   switch (id) {
      case IDM_SEND:
			// sendfax dialog
         hwndChild=GetMDIActiveChild(hwndClient);
			DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SENDDIAL), hwnd,
		                     SendDialDlgProc, (LPARAM) hwndChild);
         break;

      case IDM_STOP:
			// stopfax dialog
         hwndChild=GetMDIActiveChild(hwndClient);
			StopFax(hwndChild);
			break;

      case IDM_DEVOPTS:
			// general fax device settings dialog
         hwndChild=GetMDIActiveChild(hwndClient);
         DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_DEVOPTS), hwnd, 
									DevOptsDlgProc, (LPARAM) hwndChild);
         break;

      case IDM_ASCIIOPTS:
			// ASCII to FAX settings dialog
         hwndChild=GetMDIActiveChild(hwndClient);
         DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_ASCIIOPTS), hwnd, 
									ASCIIOptsDlgProc, (LPARAM) hwndChild);
         break;

      case IDM_WINDOWICONS:
         SendMessage(hwndClient, WM_MDIICONARRANGE, 0L, 0L);
         break;

      case IDM_WINDOWTILE:
         SendMessage(hwndClient, WM_MDITILE, 0L, 0L);
         break;

      case IDM_WINDOWCASCADE:
         SendMessage(hwndClient, WM_MDICASCADE, 0L, 0L);
         break;

      case IDM_WINDOWCLOSEALL:
         CloseAllChildren();
         break;

      case IDM_OPEN:
			// open/active a fax device
			if (FaxBoardCount == 0) {
				// no fax boards in system!
				MessageBox(hwnd, "No VFX/xxx boards found in system!", "Faxdemo Error", MB_OK|MB_ICONHAND);
				break;
			}
         if (DialogBox(hInst, MAKEINTRESOURCE(IDD_OPENDEV), hwnd, 
								DevOpenDlgProc) == IDOK) {
            // open the device
            OpenFaxDevice(szNewDevName);
            };
         break;

      case IDM_CLOSE:
			// close a fax device
         hwndChild = GetMDIActiveChild(hwndClient);
         CloseFaxDevice(hwndChild);
         break;

      case IDM_HELP:
			WinHelp(hwnd, "fdemo.hlp", HELP_CONTENTS, 0);
         break;

      case IDM_ABOUT:
         DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
         break;

      case IDM_EXIT:
         // close fax devices and if not cancelled, exit program
         if (CloseAllChildren())  {
            SendMessage(hwnd, WM_CLOSE, 0, 0L);
         }
         break;

      default:
         // forward all other messages to default handler
         FORWARD_WM_COMMAND(hwnd, id, hwndCtl, codeNotify, FrameDefProc);
         break;
   }
}   

/************************************************************
 *        NAME: FrameOnSysCommand
 * DESCRIPTION: Check for app being closed from System memu
 ************************************************************/
void FrameOnSysCommand(HWND hwnd, UINT cmd, int x, int y)   
{
   if ((cmd&0xFFF0) == SC_CLOSE)  {
      // close the app
      if (CloseAllChildren() == FALSE) {
         // if user didn't close all windows, then eat message
         return;
         }
      }

   // otherwise pass it thru to default handler
   FORWARD_WM_SYSCOMMAND(hwnd, cmd, x, y, FrameDefProc);
}   

/************************************************************
 *        NAME: FrameOnSRLNotifyEvent
 * DESCRIPTION: SRL notification Events come here for ALL child
 *              windows.  Determine child window and forward msg
 *        NOTE: ChildOnSRLNotifyEvent removes event from queue
 ************************************************************/
int WINAPI FrameOnSRLNotifyEvent(HWND hwnd, int evttype, int devhandle)
{
   LPDEVDATA lpDevData;
   HWND hwndChild;

   // wierd looking for() statement to cycle thru MDI child windows
   for (hwndChild= GetWindow(hwndClient, GW_CHILD);
        hwndChild;
        hwndChild= GetWindow(hwndChild, GW_HWNDNEXT)) {
      
   	// Skip icon title windows
   	if (GetWindow(hwndChild, GW_OWNER))
	      continue;

      // Skip ones that have no DEVDATA structure      
      if ((lpDevData = GetDevPtr(hwndChild)) == NULL)
         continue;

		// determine which handle to compare to by determining
		// if its a fax or voice event
      if ((evttype >= TFX_FAXSEND) && (evttype <= TFX_PHASED))  {
         // fax event
         if (lpDevData->faxhandle == devhandle)  {
            // found it, forward message
            FORWARD_WM_SRLNOTIFYEVENT(hwndChild, evttype, devhandle, SendMessage);
            return 0;
            }
         }
      else {
         // some other event, compare against voice handle
         if (lpDevData->voicehandle == devhandle)  {
            // found it, forward message
            FORWARD_WM_SRLNOTIFYEVENT(hwndChild, evttype, devhandle, SendMessage);
            return 0;
            }
         }
      }

   // if we get here, it's an unhandled event
   MsgBoxPrintf(NULL, "SRL Event Error", MB_OK, "Unhandled SRL event, device %s, event 0x%x", 
							ATDV_NAMEP(devhandle), evttype);
	// clear event from SRL queue
   sr_waitevt(0);

   return 0;      
}   

/************************************************************
 *        NAME: FrameDefProc()
 * DESCRIPTION: Our default Frame proc that takes 4 normal windows 
 *              parameters.  Needed so we can use FORWARD_XX_XXXX
 *              macro.
 ************************************************************/
long WINAPI FrameDefProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam)
{
   // call real default frame procedure, passing in client window handle
   return DefFrameProc(hwnd, hwndClient, msg, wParam, lParam);
}   

/************************************************************
 *        NAME: FrameWndProc()
 * DESCRIPTION: Main window's window procedure.  Process
 *              Menu commands and forward SRL events to proper
 *              child window.
 ************************************************************/
long WINAPI FrameWndProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam)
{

   switch (msg) {
      HANDLE_MSG(hwnd, WM_CREATE, FrameOnCreate);
      HANDLE_MSG(hwnd, WM_COMMAND, FrameOnCommand);
      HANDLE_MSG(hwnd, WM_SYSCOMMAND, FrameOnSysCommand);
      HANDLE_MSG(hwnd, WM_CLOSE, DestroyWindow);   // call windows function with handle
      HANDLE_MSG(hwnd, WM_SRLNOTIFYEVENT, FrameOnSRLNotifyEvent);
      case WM_DESTROY:
         PostQuitMessage(0);
         break;

      default:
         return FrameDefProc(hwnd, msg, wParam, lParam);
   }
}   

/************************************************************
 *        NAME: ChildOnCreate
 * DESCRIPTION: New child window created, device opened and
 *              initialized, device placed onhook
 ************************************************************/
BOOL ChildOnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
{
   LPDEVDATA lpDevData;
   int  temp;

   // reset pointer in window data in case of error
   SetDevPtr(hwnd, NULL);

   if ((lpDevData = malloc(sizeof(DEVDATA))) == NULL)  {
      return(FALSE);
      }

   ZeroMemory(lpDevData,sizeof(DEVDATA));

   // init DevData structure with default information
   GetWindowText(hwnd,lpDevData->devname,10);
   lpDevData->hwnd = hwnd;

   // init receive fax count
   lpDevData->rxcount = 0;

   // default ASCII parameters
   memcpy(&lpDevData->asciidata, &dftasciidata, sizeof(DF_ASCIIDATA));
   SetDevPtr(hwnd,lpDevData);

   lpDevData->state = ST_INIT;

	// open the voice device and fax device
   if ((lpDevData->voicehandle=dx_open(lpDevData->devname, 0)) == -1)  {
      StatusMsg(hwnd, "Error 0x%x opening %s for voice\n", 
						ATDV_LASTERR(SRL_DEVICE), lpDevData->devname);
      return(FALSE);
      }

   if ((lpDevData->faxhandle=fx_open(lpDevData->devname, 0)) == -1)  {
      StatusMsg(hwnd, "Error 0x%x opening %s for fax\n", 
						ATDV_LASTERR(SRL_DEVICE), lpDevData->devname);
      return(FALSE);
      }
   
	// initialize the fax channel

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -