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

📄 dlgfunc.cpp

📁 西门子交换机和Dialogic语音板卡连接驱动编程示例
💻 CPP
字号:
///////////////////////////////////////////////////////////
//          NAME: dlgfunc.h
//   DESCRIPTION: Dialog window implementation functions. These functions implement
//                the Siemens OptiSet MWI send and delete message operations.
//                These functions are called upon user selection on command buttons
//                on Dialog boxes. The MWI send and delete algorithm is implemented 
//                here. If cut and pasting code, you may need to remove Windows specific
//                code (cursor, logging, callback function types, dialog box etc...).
//
//////////////////////////////////////////////////////////
#define STRICT

#include <stdio.h>
#include <string.h>

#include <srllib.h>
#include <dxxxlib.h>
#include <d42lib.h>

#include "resource.h"

#include "main.h"
#include "dlgfunc.h"

extern   HCURSOR   g_hCursor;      // Hour glass cursor handle
extern   HCURSOR   g_hCursorA;	   // Arrow cursor handle

extern TESTINFO  g_TestInfo;               // Test settings info structure
extern CHANINFO  g_ChanInfo[MAXCHAN+1];	   // Channel info structure




///////////////////////////////////////////////////////////
//          NAME: ChannelDialogicFunc
//   DESCRIPTION: Window Callback Function for opening channel
//                
//
//////////////////////////////////////////////////////////
BOOL CALLBACK ChannelDialogFunc(HWND hdwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
char szBuff[80];
int nBrd, nChan;
char szDevName[20];
   
   // Process command from the dialog box
switch(message)
{
	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
			case IDOK:
				GetDlgItemText(hdwnd,IDC_CHANNEL,szBuff,9);
				g_TestInfo.nChannel = atoi(szBuff);

				g_ChanInfo[g_TestInfo.nChannel].nDevHandle = -1;
				nBrd  = ((g_TestInfo.nChannel-1)/4) + 1;
				nChan = g_TestInfo.nChannel%4;
      
				if (nChan==0)
				{
					nChan=4;
				}

				sprintf(szDevName,"dxxxB%dC%d",nBrd,nChan);  // VOX device name

				if ((g_ChanInfo[g_TestInfo.nChannel].nDevHandle = dx_open(szDevName, 0)) == -1)
				{
					sprintf(szBuff,"ERROR! dx_open failed!      Device (%s)",szDevName);
					LOGERROR(g_TestInfo.nChannel,szBuff);
					OUTPUT(g_TestInfo.nChannel, szBuff);
				}
				else
				{
					OUTPUT(g_TestInfo.nChannel, "Opened successfully");
				}

				EndDialog(hdwnd, 0);
				break;

			case IDCANCEL:
				EndDialog(hdwnd, 0);
				break;
			
			default:
				break;
		}
		
		break;

	case WM_INITDIALOG:
		sprintf(szBuff,"%d",g_TestInfo.nChannel);
		SetDlgItemText(hdwnd,IDC_CHANNEL,(LPCTSTR)szBuff);
		return(1);
		break;

		default:
			break;
}


return(FALSE);
}

///////////////////////////////////////////////////////////
//          NAME: SendMessageDialogicFunc
//   DESCRIPTION: Window Callback Function for sending message
//                
//
//////////////////////////////////////////////////////////
BOOL CALLBACK SendMessageDialogFunc(HWND hdwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
char szBuff[100], szBuff1[100];
   
   // Process command from the dialog box
switch(message)
{
	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
			case IDOK:
				SetCursor(g_hCursor); 
				GetDlgItemText(hdwnd,IDC_SENDMESSAGE,szBuff,9);
				g_TestInfo.nExtension = atoi(szBuff); 
				sprintf(szBuff1, "*68%s,\x1BKM,\x1BKM", szBuff);  // ESC KM is select key, need to send twice to send
				                                                  // "Please call back message"
				if (dx_dial(g_ChanInfo[g_TestInfo.nChannel].nDevHandle, szBuff1, NULL, EV_SYNC) == -1)
				{
					sprintf(szBuff,"ERROR! dx_dial failed!  DevHandle",g_ChanInfo[g_TestInfo.nChannel].nDevHandle);
					LOGERROR(g_TestInfo.nChannel,szBuff);
					OUTPUT(g_TestInfo.nChannel, szBuff);
					SetCursor(g_hCursorA);
					EndDialog(hdwnd, 0);
					break;
				}

				Sleep(1000);  // allow time for last message in send sequence to enter display buffer
				d42_display(g_ChanInfo[g_TestInfo.nChannel].nDevHandle, szBuff); 
				
				if (strncmp(szBuff, "Currently not possible",22) == 0)
				{
					LOGERROR(g_TestInfo.nChannel,szBuff);
					SetCursor(g_hCursorA);
					EndDialog(hdwnd, 0);
					MessageBox(NULL,"Cannot Send Message\nReached This Extensions\n Message Limit","MESSAGE",MB_OK|MB_TASKMODAL);
					break;
				}

				if (strncmp(szBuff, "Sent to",7) == 0)
				{
					SetCursor(g_hCursorA);
					EndDialog(hdwnd, 0);
					MessageBox(NULL,"Message Sent","MESSAGE",MB_OK|MB_TASKMODAL);
					g_ChanInfo[g_TestInfo.nChannel].nMsgCnt++;   // increment channel msg counter. NOTE: this count
					                                             // obviously will be lost upon app exit. If proper 
					                                             // count is needed upon app restart you must save 
					                                             // this count to a file. Siemens switch does not 
					                                             // provide total message sent count.
					break;
				}
				else
				{
					OUTPUT(g_TestInfo.nChannel, szBuff);
					SetCursor(g_hCursorA);
					EndDialog(hdwnd, 0);
					MessageBox(NULL,"Message NOT Sent\nWait 60 seconds before\nselecting another option","ERROR",MB_OK|MB_TASKMODAL);
					break;
				}

				break;

			case IDCANCEL:
				EndDialog(hdwnd, 0);
				break;
			
			default:
				break;
		}
		
		break;

	case WM_INITDIALOG:
		if (g_ChanInfo[g_TestInfo.nChannel].nDevHandle == -1)
		{
			SetCursor(g_hCursorA);
			EndDialog(hdwnd, 0);
			MessageBox(NULL,"No channel selected. Must select voice channel before sending","ERROR!",MB_OK|MB_TASKMODAL);
			break;
		}

		sprintf(szBuff,"%d",g_TestInfo.nExtension);
		SetDlgItemText(hdwnd,IDC_SENDMESSAGE,(LPCTSTR)szBuff);
		return(1);
		break;

		default:
			break;
}


return(FALSE);
}



///////////////////////////////////////////////////////////
//          NAME: DeleteMessageDialogicFunc
//   DESCRIPTION: Window Callback Function for deleting a message
//                
//
//////////////////////////////////////////////////////////
BOOL CALLBACK DeleteMessageDialogFunc(HWND hdwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
char szBuff[100], szBuff1[100];
static int nCnt=1;      
BOOL bRet;

// Process command from the error dialog box
switch(message)
{
	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
			case IDOK:
				SetCursor(g_hCursor);
				// Get edit box data in the dialog box
				GetDlgItemText(hdwnd,IDC_EXTENSION,szBuff,9);
				g_TestInfo.nExtension = atoi(szBuff); 
				
				sprintf(szBuff1, "\x1BKO\x1BKM");  // ESC KO is -> arrow key ESC KM is select key, need to send twice to send

				if (dx_dial(g_ChanInfo[g_TestInfo.nChannel].nDevHandle, szBuff1, NULL, EV_SYNC) == -1)
				{
					sprintf(szBuff,"ERROR! dx_dial failed!  DevHandle",g_ChanInfo[g_TestInfo.nChannel].nDevHandle);
					LOGERROR(g_TestInfo.nChannel,szBuff);
					OUTPUT(g_TestInfo.nChannel, szBuff);
					SetCursor(g_hCursorA);
					EndDialog(hdwnd, 0);
					break;
				}

				Sleep(500);

				d42_display(g_ChanInfo[g_TestInfo.nChannel].nDevHandle, szBuff); 
				
				if (strncmp(szBuff, "Deleted",7) == 0 || strncmp(szBuff, "List is empty",13) == 0)
				{

					sprintf(szBuff, "\x1BKO\x1BKM");  // send 1 -> arrow key and 1 select key after deleting

					if (dx_dial(g_ChanInfo[g_TestInfo.nChannel].nDevHandle, szBuff, NULL, EV_SYNC) == -1)
					{
						sprintf(szBuff,"ERROR! dx_dial failed!  DevHandle",g_ChanInfo[g_TestInfo.nChannel].nDevHandle);
						LOGERROR(g_TestInfo.nChannel,szBuff);
						OUTPUT(g_TestInfo.nChannel, szBuff);
						SetCursor(g_hCursorA);
						EndDialog(hdwnd, 0);
						break;
					}
					
					SetCursor(g_hCursorA);
					EndDialog(hdwnd, 0);
					MessageBox(NULL,"Message Deleted","MESSAGE",MB_OK|MB_TASKMODAL);
					g_ChanInfo[g_TestInfo.nChannel].nMsgCnt--; // decrement channel msg counter
					break;
				}
				else
				{
					OUTPUT(g_TestInfo.nChannel, szBuff);
					SetCursor(NULL);
					// Need to wait until switch clears displayed message and resets to expected message. Otherwise
					// next call of d42_display may not receive expected message.
					MessageBox(NULL,"Message NOT Deleted\nWait 60 seconds before\nselecting another option","ERROR",MB_OK|MB_TASKMODAL);
					EndDialog(hdwnd, 0);
					break;
				}

				break;

			case IDC_EXTENSIONNEXT:
				SetCursor(g_hCursor);

				// Scroll through all extension numbers sent on this channel
				// Siemens switch does not have a command to indicate total messages sent. Also, upon repeated selection 
				// of Next keys, extension numbers will loop around. No indication is given that end of list has been 
				// reached. So an program counter is used. If program is terminated with undeleted messages sent, program
				// will not move through all extension numbers since counter will be reset. This counter could be put into
				// a file if count is needed upon app restart.
				if (nCnt < g_ChanInfo[g_TestInfo.nChannel].nMsgCnt)
				{
					sprintf(szBuff, "\x1BKO\x1BKO\x1BKM");  // send 2 -> arrow keys and 1 select key

					if (dx_dial(g_ChanInfo[g_TestInfo.nChannel].nDevHandle, szBuff, NULL, EV_SYNC) == -1)
					{
						sprintf(szBuff,"ERROR! dx_dial failed!  DevHandle",g_ChanInfo[g_TestInfo.nChannel].nDevHandle);
						LOGERROR(g_TestInfo.nChannel,szBuff);
						OUTPUT(g_TestInfo.nChannel, szBuff);
						SetCursor(g_hCursorA);
						EndDialog(hdwnd, 0);
						break;
					}

					d42_display(g_ChanInfo[g_TestInfo.nChannel].nDevHandle, szBuff);
					memset(szBuff1, '\0', sizeof(szBuff1));
					strncpy(szBuff1, &szBuff[12],3);  // get extension number out of message string, format - "Message to: 102"
													  // If extension number is greater then 3 change length of copy to match
					bRet=SetDlgItemText(hdwnd,IDC_EXTENSION,(LPCTSTR)szBuff1);
					nCnt++;
					SetCursor(g_hCursorA);
				}
				else
				{
					SetCursor(g_hCursorA);
					MessageBox(NULL,"End of Messages","MESSAGE",MB_OK|MB_TASKMODAL);
				}

				break;

			case IDCANCEL:
				EndDialog(hdwnd, 0);
				break;

			default:
				break;
		}
		
		break;

	case WM_INITDIALOG:
		SetCursor(g_hCursor);

		if (g_ChanInfo[g_TestInfo.nChannel].nDevHandle == -1)
		{
			SetCursor(g_hCursorA);
			EndDialog(hdwnd, 0);
			MessageBox(NULL,"No channel selected. Must select voice channel before Deleting","ERROR!",MB_OK|MB_TASKMODAL);
			break;
		}

		nCnt = 1;

		// Initialize the edit box in the dialog box
		if (dx_dial(g_ChanInfo[g_TestInfo.nChannel].nDevHandle, "#68", NULL, EV_SYNC) == -1)
		{
			sprintf(szBuff,"ERROR! dx_dial failed!  DevHandle",g_ChanInfo[g_TestInfo.nChannel].nDevHandle);
			LOGERROR(g_TestInfo.nChannel,szBuff);
			OUTPUT(g_TestInfo.nChannel, szBuff);
			SetCursor(g_hCursorA);
			EndDialog(hdwnd, 0);
			break;
		}
		else
		{
			Sleep(500);
			d42_display(g_ChanInfo[g_TestInfo.nChannel].nDevHandle, szBuff);

			if (strncmp(szBuff, "List is empty",13) == 0)
			{
				SetCursor(g_hCursorA);
				EndDialog(hdwnd, 0);
				MessageBox(NULL,"No Messages to Delete.","MESSAGE",MB_OK|MB_TASKMODAL);
				g_ChanInfo[g_TestInfo.nChannel].nMsgCnt = 0;  // reset channel msg counter
				break;
			}

			if (strncmp(szBuff, "Message to:",11) != 0)
			{
				sprintf(szBuff1,"ERROR! Unexpected Display Message - %s",szBuff);
				LOGERROR(g_TestInfo.nChannel,szBuff1);
				OUTPUT(g_TestInfo.nChannel, szBuff1);
				SetCursor(g_hCursorA);
				EndDialog(hdwnd, 0);
				break;
			}

			memset(szBuff1, '\0', sizeof(szBuff1));
			strncpy(szBuff1, &szBuff[12],3);  // get extension number out of message string, format - "Message to: 102"
			bRet=SetDlgItemText(hdwnd,IDC_EXTENSION,(LPCTSTR)szBuff1);
			SetCursor(g_hCursorA);
		}

		break;

	default:
		break;
}

return(FALSE);
}

⌨️ 快捷键说明

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