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

📄 inter.c

📁 Dialogic数字板卡示例程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Provides the Windows interface for the previously console
 * application
 *
 * FEATURES: This is a simple single window interface code. It has the
 * entry point to the application, and upon menu request it creates the
 * thread that initializes the Dialogic devices and starts the corresponding
 * voice threads.
 *
 */
#include <stdio.h>
#include "inter.h"

#define MAX_PRO_NAME 30
#define MAXBRDCNT 50
typedef struct {
	int				NumBrdDevs;
	char			BrdNames[ MAXBRDCNT ][ 8 ];
	unsigned char	frontend[ MAXBRDCNT ];
} DEVICE;

DEVICE Vox;
DEVICE Dti;
FILE   *fp;
/* 
 *	global variables ---- these variables are required in many instances
 *	of this application so they are maintained globally
 */
char szAppName[] = "AnsrMT Demo";	          /* the name of this app*/
char szIconName[] = "Dialogic";				  /* the name of this icon */
char szChildClass[] = "Child Window Class";	  /* name of the child class of window */

HWND ghwndMain;							/* handle to the main window */
HINSTANCE	hInst;
HANDLE hExitEvent;

int	 maxchans=4;							/* Default Number of D/4x Channels to use */
int  d4xbdnum;								/* Default D/4x Board Number to Start use */
int  dtibdnum;								/* Default DTI Board Number to Start use */
int  frontend=CT_NTANALOG;					/* Default network frontend is ANALOG */
int  routeag;								/* Route analog frontend to resource ??? */
char protocol[ MAX_PRO_NAME ] = { "ISDN" };	/* The name of protocol for GC */

extern char version[];
extern char dialogic[];
extern char dialogic2[];   


char gRowVal[NUM_ROWS][MAX_STR_LEN];

extern void StopDialogic(void );
extern WINAPI InitDialogic (HWND *tempHwnd); // opens all the channels up!




/***************************************************************
*	FUNCTION :		WinMain()
*	DESCRIPTION :	This is the main() of a windows app.  It contains
*					the Windows msg loop.
*	INPUTS :		the instance data, command line data
*	OUTPUTS :		response to OS
****************************************************************/
int WINAPI WinMain(
	HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPSTR lpCmdLine,
	int nCmdShow)

{
	MSG msg;
	HANDLE hAccelTable;
	
//	fp = fopen( "test.out", "w" );
	
	if (!hPrevInstance) 				/* if this is the first instance of this app */
	{
		if (!InitApplication(hInstance))
			return(FALSE);
	}										        /* exits if unable to initialize */

	hAccelTable = LoadAccelerators(hInstance, szAppName);


	if (!InitMainWndInstance(hInstance, nCmdShow))
		return(FALSE);						/* perform initializations that apply to a */

		
	while (GetMessage(&msg,			/* message structure */
		NULL,								      /* handle of window recieving message */
		0,									      /* lowest msg to examine */
		0))									      /* highest message to examine */
	{
		if (!TranslateAccelerator (ghwndMain, hAccelTable, &msg))
			TranslateMessage(&msg);
	  DispatchMessage(&msg);
	}

//	fclose( fp );

	return(msg.wParam);						/* returns value from PostQuitMessage */

	
}


/************************************************************************
*	FUNCTION :		InitApplication()
*	DESCRIPTION :	this function creates and registers the windows that
*					are used in this application
*	INPUTS :		The instance of the application.  
*	OUTPUTS :		TRUE or FALSE
************************************************************************/
BOOL InitApplication(HINSTANCE hInstance)
{
	WNDCLASS wc;
	

    // Create an event object to allow graceful exit of worker threads
    hExitEvent = CreateEvent(NULL,	// no security attributes  
                            TRUE ,  // manual-reset event 
                            FALSE,	// initial state is reset
                            NULL 	// no event-object name  
                            );
    
	
	/* fill in the class structure now */

	wc.style		= CS_HREDRAW | CS_VREDRAW;	        /* class style */
	wc.lpfnWndProc	= (WNDPROC)WndProc;			        /* window procedure	*/
	wc.cbClsExtra	= 0;						        /* no per class extras */
	wc.cbWndExtra	= sizeof(LONG);				        /* per child handle info */
	wc.hIcon		= LoadIcon (hInstance, MAKEINTRESOURCE(PHONE_ICON)); // Icon name from .RC
	wc.hInstance 	= hInstance;				        /* handle to module */
	wc.hCursor		= LoadCursor(NULL, IDC_ARROW);      /* handle to icon */
	wc.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);         /* defualt back color */
	wc.lpszMenuName	= MAKEINTRESOURCE(IDR_MENU1);	    /* Menu name from .RC */
	wc.lpszClassName= szAppName;				        /* name to register classs */
	

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

	return(TRUE);
}


/****************************************************************************
*	FUNCTION:		InitMainWndInstance(HINSTANCE, int)
*	DESCRIPTION :	Saves instance handle and creates main window
*	INPUTS :		The instance of the  application and the Command concerning
*					the visibility of the window (MINIMIZED/MAXIMIZED)
*	OUTPUTS :		TRUE/FALSE
*	COMMENTS:		This function is called at initialization time for every 
*					instance of this application.  This function performs 
*					initialization tasks that cannot be shared by multiple instances.
*					In this case, we save the instance handle in a static variable 
*					and	create and display the main program window.
*
****************************************************************************/

BOOL InitMainWndInstance(
	HINSTANCE	hInstance,
	int	nCmdShow)

{
  int i;

	ghwndMain = CreateWindow(
		szAppName,						      /* text for window titlebar */
		szAppName,	 					      /* Text for title bar */
		WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,	/* window style */
		CW_USEDEFAULT,					    /* x position on screen */
		CW_USEDEFAULT,					    /* y position on screen */
		CW_USEDEFAULT,					    /* default width	  */
		MAIN_HEIGHT,					      /* default height */
		NULL,							          /* parent window */
		NULL,							          /* handle to the Menu for this window */
		hInstance,						        /* This instacne owns the window	*/
		NULL);							        /* we don't use any data in our WM_CREATE*/

	if (!ghwndMain)							      /* if the Create failed, return false */
		return(FALSE);

  hInst = hInstance;                /* save in global variable */

  for (i = 0; i < NUM_ROWS; i++)
    {
    gRowVal[i][0] = 0;
    }

	SetFocus(ghwndMain);						    /* give the focus to this window */
	
	ShowWindow(ghwndMain, nCmdShow);		/* Make the window visibe return success */
    UpdateWindow(ghwndMain);

    disp_init(ghwndMain);
    disp_msg(ghwndMain, "Select Action/Start to begin or first select options");
	
	return(TRUE);
}

/****************************************************************************
*	FUNCTION:		WndProc(HWND, UINT, WPARAM, LPARAM)
*	DESCRIPTION :	Processes messages for the main window of the application
*	INPUTS :		the handle to the window (can be used by more than one)
*					the message and message specific parameters
*	OUTPUTS :		NA
*	CAUTIONS :		This function is called internally by Windows (it is a 
*					callback function) anytime an event occurs within (or that
*					affects) that window.
****************************************************************************/

WINAPI WndProc(
		HWND hWnd,						/* window handle	*/
		UINT message,					/* type of message */
		WPARAM wParam,					/* additional information */
		LPARAM lParam)					/* additional information */
{
	PAINTSTRUCT ps;
	HDC  hDC;



	switch ( message )
	{

    HANDLE_MSG( hWnd, WM_COMMAND, ANSREXW_OnCommand );
	default:
	    return DefWindowProc( hWnd, message, wParam, lParam );

    case WM_CLOSE:
        strcpy( gRowVal[ CHAN_BASE_ROW - 1 ], "Closing dialogic devices down..." );
        InvalidateRect( hWnd, NULL, TRUE );
        UpdateWindow( hWnd );
        SetEvent( hExitEvent );
        DestroyWindow( hWnd );
        return 0L;
        break;
 
	case WM_CREATE:
        BuildChanName( hWnd );
        break;

	case WM_DESTROY:
        PostQuitMessage( 0 );
	    return 0L;
		break;

	case WM_SHOWWINDOW:
	case WM_PAINT:
        // the ps contains the information on the
        // rectangle to paint
        hDC = BeginPaint( hWnd, &ps );	
        RedrawRows( hWnd, hDC );   	
		EndPaint( hWnd, &ps );
		break;
 	}
	return 0L;
}

/***************************************************************************
*	FUNCTION :		PrintError()
*	DESCRIPTION :	This function will take any string parameters in the printf
*					format and will appent the error number of the last Windows 
*					error to it and display it in a MessageBox
*	INPUTS :		the printf wtyle string
*	OUTPUTS :		the message box
***************************************************************************/
void PrintError(char *szFormat, ...)
{
	char szBuffer[256];
	va_list pArguments;

	
	va_start(pArguments,szFormat);
	vsprintf(szBuffer, szFormat, pArguments);
	
	MessageBox(NULL, szBuffer, "Program Error", MB_APPLMODAL|MB_OK);
}


/***************************************************************************
*	FUNCTION :		RedrawRows(HWND hwnd, HDC hdc)
*	DESCRIPTION :	Redraws, row by row, the string which are to appear in our
*               main window.  Note these rows are found in the global
*               variable "gRowVal[][]".
*	INPUTS : the window to draw them in (here, the main window always)
*            the windows DC
*	OUTPUTS : rows rewitten in our main window
***************************************************************************/
void RedrawRows
  (HWND hwnd, HDC hdc)
{ /* We want to be pretty, but we want to be simple to.  So to be pretty we will
   * make the header lines blue, the status line red, and the rest black.  To
   * be simple, we will make the header lines blue, the status line red, and the
   * rest black.
   */
  int i;
  RECT Rect;
  HFONT hFont, hOldFont;

  
  // get the actual window rectangle and use the right and left coordinates
  // later
  GetClientRect(hwnd, &Rect);

  // Create a Times New Roman font
  hFont = CreateFont(FONT_HEIGHT, FONT_WIDTH, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET,
      OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH ,
      FONT_TYPE);

  // Force font matching and save the old font
  SetMapperFlags(hdc, 1);

  //hOldFont=to Select Object
  hOldFont = SelectObject(hdc, hFont);

   
  /* note that since we do not know what channel was the one
  ** that sent the message, we need to go thru all of them,
  ** however the DC is only valid for the rectangle that
  ** got invalidated, this way the overhead is only on the
  ** for loop but not in repainting the whole window.
  */

  // Set the text attributes
  SetTextColor(hdc, RGB(0, 0, 255)); // blue for header lines
  for (i = 0; i < CHAN_BASE_ROW - 1; i++) // header lines
    {
		
        Rect.top=i*ROW_HEIGHT;
        Rect.bottom=(i+1)*ROW_HEIGHT;
        
        DrawText(hdc, gRowVal[i], strlen(gRowVal[i]),&Rect,DT_CENTER );
    }

  // draw a line
  i = CHAN_BASE_ROW-1;
  Rect.top=i*ROW_HEIGHT;
  Rect.bottom=(i+1)*ROW_HEIGHT;

  MoveToEx(hdc, Rect.left, Rect.top + ROW_HEIGHT/2,NULL);
  LineTo(hdc,Rect.right,Rect.top + ROW_HEIGHT/2);

  // draw the message line
  SetTextColor(hdc, RGB(255, 0, 0)); // red for status line

  i = CHAN_BASE_ROW-1;
  Rect.top=(i+1)*ROW_HEIGHT;
  Rect.bottom=(i+2)*ROW_HEIGHT;

  DrawText(hdc, gRowVal[i], strlen(gRowVal[i]),&Rect,DT_CENTER );

  SetTextColor(hdc, RGB(0, 0, 0)); // black for channel info rows
  for (i = CHAN_BASE_ROW; i < CHAN_BASE_ROW+maxchans; i++)
    {
    // since we draw one line at a time, get the appropriate rect
    //coordinates
    Rect.top=(i+1)*ROW_HEIGHT;
    Rect.bottom=(i+2)*ROW_HEIGHT;
    DrawText(hdc, gRowVal[i], strlen(gRowVal[i]),&Rect,DT_LEFT );
    }
 
  SelectObject(hdc, hOldFont);
  DeleteObject(hFont); 

}



/*************************************************************************************
 *        NAME : ANSREXW_OnCommand()
 * DESCRIPTION : Message Handler for WM_COMMAND
 *    CAUTIONS : none.
 *************************************************************************************/

void ANSREXW_OnCommand(HWND hWnd, int id, HWND hwndCtl, UINT codeNotify)
{
    DWORD	ThreadId;
    HANDLE  hThread=NULL;


   switch (id) {
		case ID_ACTION_EXIT:
				DestroyWindow(hWnd); // post WM_DESTROY message for WndProc to exit app
				break;
		case ID_OPTIONS_CSETTINGS:
				DialogBox(hInst, MAKEINTRESOURCE(OPTION), hWnd, CSET_WndProc);
				break;
		case ID_HELP_ABOUT:
                DialogBox(hInst, MAKEINTRESOURCE(ABOUTBOX), hWnd, AboutDlgProc);
				break;

        case ID_HELP_HELPTOPICS:
                if (!WinHelp(hWnd, (LPCTSTR) "Ansrmt.hlp", (UINT) HELP_INDEX,(DWORD) 0)) {
                    MessageBox(ghwndMain, "Unable to activate help",
                            szAppName, MB_APPLMODAL|MB_OK|MB_ICONHAND);
                }
                break;

		case ID_ACTION_START:		// create threads here and gray the "start" menu and

                // if the thread had been created before, close the handle to clean up stack
                if (hThread != NULL)
                    CloseHandle(hThread);
                // spawn the thread that initializes the channels
	            if (!( hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)InitDialogic,
                    &ghwndMain, 0, &ThreadId )) )
                {
		            MessageBox(ghwndMain, "Unable to create thread.", szAppName, MB_APPLMODAL|MB_OK );
		        }

				// ungrey the "stop" menu
				EnableMenuItem(GetMenu(hWnd), ID_ACTION_STOP, MF_ENABLED );

				// disable and gray the Options and Action/Start menu items
				EnableMenuItem(GetMenu(hWnd), ID_OPTIONS_CSETTINGS, MF_DISABLED | MF_GRAYED	);
				EnableMenuItem(GetMenu(hWnd), ID_ACTION_START, MF_DISABLED | MF_GRAYED	);
								
				break;

⌨️ 快捷键说明

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