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

📄 fdemo.c

📁 传真示例
💻 C
📖 第 1 页 / 共 5 页
字号:
      }
   
   // send message to destroy MDI child window
   // ChildOnDestroy() will close devices and release DEVDATA structure
   SendMessage(hwndClient, WM_MDIDESTROY, (WPARAM) hwnd, 0);

   // update menu item states in case this was last child window
   GrayMenuItems();  
   return(TRUE);
   
}   

/************************************************************
 *        NAME: AlreadyOpen()
 * DESCRIPTION: Returns child window of device if already open
 *              or NULL if not open, searches thru MDI child 
 *              window titles for matching string
 *     RETURNS: Child window for device/NULL if not open
 ************************************************************/
HWND AlreadyOpen(char *pName)
{
   HWND  hwndCheck;
   char  szBuff[MAXDEVNAMELEN];

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

      GetWindowText(hwndCheck, szBuff, sizeof(szBuff));

      if (_stricmp(szBuff, pName) == 0)  {
         // found matching child window, return handle
         return(hwndCheck);
         }

      }
   // matching child window was not found
   return(NULL);
}    

/************************************************************
 *        NAME: StopFax()
 * DESCRIPTION: Stop fax/voice processing and return channel to idle status
 *     RETURNS: success, failure
 ************************************************************/
BOOL StopFax(HWND hwnd)
{
   LPDEVDATA lpDevData; 

   if ((lpDevData = GetDevPtr(hwnd)) != NULL)  {
		if (MsgBoxPrintf(hwnd, "Stop Fax", MB_YESNO|MB_ICONQUESTION, 
						"Issue a stop to device \"%s\" and return to idle state?", lpDevData->devname) != IDYES) {
			return FALSE;
			}
		// issue a voice stop regardless of voice or fax function active
		if ((lpDevData->state == ST_RXRECVFAX) || (lpDevData->state == ST_TXSENDFAX)) {
			dx_stopch(lpDevData->faxhandle, EV_ASYNC);
			}
		else {
			dx_stopch(lpDevData->voicehandle, EV_ASYNC);
			}
		return TRUE;
		}
	else {
		return FALSE;
	}

}
/************************************************************
 *        NAME: CloseAllChildren
 * DESCRIPTION: Close all devices, checking for inactive first
 *     RETURNS: success, failure
 ************************************************************/
BOOL CloseAllChildren(void)
{
   HWND  hwnd;
   
   while (hwnd = GetWindow(hwndClient, GW_CHILD)) {
   	// Skip icon title windows
   	if (GetWindow(hwnd, GW_OWNER))
	      continue;

      if (CloseFaxDevice(hwnd) == FALSE)  {
         // user cancelled because of active device
         // don't bother checking rest
         return(FALSE);
         }   
      }
   return(TRUE);
}   

/************************************************************
 *        NAME: GrayMenuItems()
 * DESCRIPTION: Gray/UnGray menu items depending on child windows
 *     RETURNS: nothing
 ************************************************************/
void GrayMenuItems(void)
{
   HWND  hwnd;
   HMENU hMenu;
   int   flag = MF_GRAYED;

   // if there are client child windows, enable menu items
   while ((hwnd = GetWindow(hwndClient, GW_CHILD)) && (flag == MF_GRAYED)) {
   	// Skip icon title windows
   	if (GetWindow(hwnd, GW_OWNER))
	      continue;

      flag = MF_ENABLED;
      }

   // use state of fFlag to enable/disable menu items
   if ((hMenu = GetMenu(hwndFrame)) != NULL)  {
      EnableMenuItem(hMenu, IDM_CLOSE, flag);
      EnableMenuItem(hMenu, IDM_SEND, flag);
      EnableMenuItem(hMenu, IDM_STOP, flag);
      EnableMenuItem(hMenu, IDM_DEVOPTS, flag);
      EnableMenuItem(hMenu, IDM_ASCIIOPTS, flag);
      EnableMenuItem(hMenu, IDM_WINDOWTILE, flag);
      EnableMenuItem(hMenu, IDM_WINDOWCASCADE, flag);
      EnableMenuItem(hMenu, IDM_WINDOWICONS, flag);
      EnableMenuItem(hMenu, IDM_WINDOWCLOSEALL, flag);
      }

}   

/************************************************************
 *        NAME: GetFaxBoards()
 * DESCRIPTION: Determine number of fax boards in system
 *              initializes an array of fax boards
 ************************************************************/
int GetFaxBoards(void)
{
	int	bdcount,i;
	int	bddev, chdev;
	char	**lpChName;
   char  szBuff[MAXDEVNAMELEN];

	// first determine number of boards in system
	sr_getboardcnt("Voice", &bdcount);

	if (bdcount <=0) {
		return FALSE;
		}

	// check each board and determine if it hase fax resources attached
	for(i=1;((i<=bdcount) && (FaxBoardCount<MAXFAXBOARDS));i++) {
	   // open the board and get list of channel device names
      wsprintf(szBuff, "dxxxB%d", i);
		if ((bddev = dx_open(szBuff, 0)) != -1) {
		  lpChName = ATDX_CHNAMES(bddev);
	      if ((chdev = dx_open(*lpChName, 0)) != -1) {
				// if channel device supports fax, add board to list
            if (ATFX_CHTYPE(chdev) != -1) {
					// add Voice/Fax board to list
					strcpy(FaxBoardArray[FaxBoardCount++],szBuff);
					}
            dx_close(chdev);
				}
         dx_close(bddev);
         }
      }
	return TRUE;
}

/************************************************************
 *        NAME: strtrim()
 * DESCRIPTION: trim any leading or trailing spaces from string
 *     RETURNS: pointer to trimmed string
 *        NOTE: replaces trailing spaces with zero byte
 *              increments pointer returned past leading spaces
 *              BUFFER WILL STILL CONTAIN LEADING SPACES
 ************************************************************/
char *strtrim(char *pStr)
{
   char *pWorkStr;

   // check for null pointer
   if (pStr == NULL) {
      return(pStr);
      }
   
   // trim trailing spaces first   
   pWorkStr = pStr+strlen(pStr);

   while ((--pWorkStr > pStr) && *pWorkStr == ' ') {
      // remove trailing space
      *pWorkStr='\0'; 
      }   

   // now trim any leading spaces
   pWorkStr = pStr;

   while ((*pWorkStr != '\0') && *pWorkStr == ' ') {
      // inc pointer to next char
      pWorkStr++; 
      }   

   return(pWorkStr);
   
}   

/************************************************************
 *        NAME: StatusMsg()
 * DESCRIPTION: vsprintf to device information buffer
 *              contents of winbuff is displayed in child window
 *              each time channel status is updated ChildOnPaint()
 ************************************************************/
void StatusMsg(HWND hwnd, char *szFormat, ...)
{
   va_list pOptArgs;
   int   ofs;
   LPDEVDATA lpDevData = GetDevPtr(hwnd);

   if (lpDevData == NULL)  {
      return;
   }
   
   ofs=strlen(lpDevData->winbuff);	// append to what is already in buffer
   va_start(pOptArgs, szFormat);
   vsprintf(&lpDevData->winbuff[ofs], szFormat, pOptArgs);

   InvalidateRect(hwnd, NULL, TRUE);
   UpdateWindow(hwnd);
   return;
   
}   

/************************************************************
 *        NAME: WinPrintfAt()
 * DESCRIPTION: vsprintf to TextOut() 
 ************************************************************/
void WinPrintfAt(HDC hdc, int row, int col, LPSTR pszFormat, ... )
{
    char    szOutput[256];
    int     cbOutput;
    va_list ArgList;

    va_start( ArgList, pszFormat );
    cbOutput = wvsprintf( szOutput, pszFormat, ArgList );
    va_end( ArgList );

    TextOut( hdc,
             col * tmAveCharWidth,
             row * tmHeight,
             szOutput,
             cbOutput );

} 

/************************************************************
 *        NAME: MsgBoxPrintf()
 * DESCRIPTION: vsprintf to MessageBox()
 *       INPUT: Same as MessageBox() with message text last 
 *              allowing variable number of args
 *     RETURNS: Same as MessageBox()
 ************************************************************/
int MsgBoxPrintf(HWND hwnd, char *szTitle, UINT fustyle, char *szFormat, ...)
{
   va_list pOptArgs;
   char  szBuff[256];
      
   va_start(pOptArgs, szFormat);
   vsprintf(szBuff, szFormat, pOptArgs);

   return(MessageBox(hwnd, szBuff, szTitle, fustyle));
   
}   

/************************************************************
 *        NAME: InitApplication(LPSTR lpCmdLine, int nCmdShow)
 * DESCRIPTION: Register Windows classes and perform 
 *              application initialization 
 ************************************************************/
BOOL InitApplication(LPSTR lpszCmdLine, int nCmdShow)
{
   WNDCLASS  wc;

   ZeroMemory(&wc,sizeof(wc));
   // Register the frame class 
   wc.style         = 0;
   wc.lpfnWndProc   = FrameWndProc;
   wc.cbClsExtra    = 0;
   wc.cbWndExtra    = 0;
   wc.hInstance     = hInst;
   wc.hIcon         = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1));
   wc.hCursor       = LoadCursor(NULL,IDC_ARROW);
   wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
   wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MENU1);
   wc.lpszClassName = szFrame;

   if (!RegisterClass (&wc)) {
      return(FALSE);
      }

      
   // Register the MDI child class 
   wc.lpfnWndProc   = ChildWndProc;
   wc.hIcon         = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1));
   wc.lpszMenuName  = NULL;
   wc.cbWndExtra    = CBWNDEXTRA;
   wc.lpszClassName = szChild;

   if (!RegisterClass(&wc))  {
      return FALSE;
      }

   // initialize current directory path for storing received faxes
   if (GetCurrentDirectory(MAXFILELEN, szRxPath) >0)  {
      // make sure it ends with a backslash      
      if (szRxPath[strlen(szRxPath)-1] != '\\') {
         strcat(szRxPath,"\\");
         }
      }

   // create the main frame window
   hwndFrame = CreateWindow(szFrame,
                           "Dialogic Fax Demo Application",
                           WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
                           CW_USEDEFAULT,
                           CW_USEDEFAULT,
                           CW_USEDEFAULT,
                           CW_USEDEFAULT,
                           NULL,
                           NULL,
                           hInst,
                           NULL);

   ShowWindow(hwndFrame, nCmdShow);
   UpdateWindow(hwndFrame);

   hAccelTable = LoadAccelerators (hInst, szAppName);

   // make sure menu items are grayed
   GrayMenuItems();  

   return TRUE;

}

/************************************************************
 *        NAME: WinMain()
 * DESCRIPTION: Main entry point to program
 ************************************************************/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   LPSTR lpszCmdLine, int nCmdShow)
{
   MSG msg;

   hInst = hInstance;

   // Create the frame and do other initialization
   if (!InitApplication(lpszCmdLine, nCmdShow))  {
      return 0;
   }

   // Enter main message loop 
    while (GetMessage(&msg, NULL, 0, 0)) {
        if (!TranslateAccelerator( hwndFrame, hAccelTable, &msg) &&
            !TranslateMDISysAccel( hwndClient, &msg)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
   // Exit
   return msg.wParam;
}

⌨️ 快捷键说明

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