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

📄 dialogs.c

📁 g729 coding ipaddressing
💻 C
📖 第 1 页 / 共 4 页
字号:
    strcpy(NewHostParams.pszHostName, phostent->h_name);
    memcpy(NewHostParams.paddr, phostent->h_addr, sizeof(IN_ADDR));

    EndDialog(hwnd, TRUE);
}

/*  NEWHOST_ONCOMMAND  --  Handle child control messages in the new
						   host dialogue.  */

static VOID NewHost_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
    HANDLE  hAsyncTask;
    SOCKERR serr;

    //  Interpret the command

    switch (id) {
    
	    case IDOK:
	        // handled below
	        break;
	
	    case IDCANCEL:
	    
	        //  Cancel any pending async operation started by this dialog
	
	        if (NewHostParams.hAsync != NULL) {
	            WSACancelAsyncRequest(NewHostParams.hAsync);
	            NewHostParams.hAsync = NULL;
	        }
	        EndDialog(hwnd, FALSE);
	        return;

#ifdef MODEM	        
	    case IDC_NEW_MODEM:
	    	{
	    		if ((WORD) SendMessage(GetDlgItem(hwnd, IDC_NEW_MODEM),
	    				BM_GETCHECK, 0, 0L)) {
		    		ShowWindow(GetDlgItem(hwnd, IDD_NEW_HOST_NAME), SW_HIDE);
		    		ShowWindow(GetDlgItem(hwnd, IDD_NEW_HOST_DIAL_STRING), SW_SHOW);
		    	} else {
		    		ShowWindow(GetDlgItem(hwnd, IDD_NEW_HOST_NAME), SW_SHOW);
		    		ShowWindow(GetDlgItem(hwnd, IDD_NEW_HOST_DIAL_STRING), SW_HIDE);
	    		}
	    	}
	    	return;
#endif	    	
	    	
        case ID_HELP:
        	displayHelpTopic(IDS_HELP_NEWCONN);
        	return;
	
	    default:
	        return;
    }

    /*  We only make it to this point if the command was OK.
        Get the host name/address from the edit field. */

    Edit_GetText(GetDlgItem(hwnd, IDD_NEW_HOST), NewHostParams.pszHostName,
                  MAX_HOST);

#ifdef MODEM
    if (IsDlgButtonChecked(hwnd, IDC_NEW_MODEM)) {
    	COMSTAT cs;
    	
    	if (modemSessions != 0) {
			MessageBox(hwnd, rstring(IDS_T_MODEM_BUSY), NULL, MB_ICONEXCLAMATION | MB_OK);
			return;
    	}
    	
    	//	Send the modem dialing command
    	
    	V GetCommError(modemHandle, &cs);
    	WriteComm(modemHandle, NewHostParams.pszHostName,
    				strlen(NewHostParams.pszHostName));
    	V GetCommError(modemHandle, &cs);
    	WriteComm(modemHandle, "\r", 1);
    	V GetCommError(modemHandle, &cs);
    				 
		//	Zero Internet address indicates modem connection
		
    	memset(NewHostParams.paddr, 0, sizeof(IN_ADDR));
    	
    	EndDialog(hwnd, TRUE);
    } else
#endif    
    {
    	LPSTR cp;
    	unsigned int port = 0;
    
	    if (NewHostParams.pszHostName[0] == '\0') {
	        return;
	    }
	    
	    /*	If a port address is specified, save it and remove from
	    	the host name.  */
	    	
	    if ((cp = strchr(NewHostParams.pszHostName, '/')) != NULL ||
	    	(cp = strchr(NewHostParams.pszHostName, ':')) != NULL) {
	    	char cb[MAX_HOST];
	    	
	    	strcpy(cb, cp + 1);
	    	port = (unsigned int) atol(cb);
	    	if (port <= 0) {
		        MsgBox(hwnd, MB_ICONSTOP | MB_OK, Format(72), *cp); 
		        return;
	    	}
	    	*cp = 0;
	    } else {
	    	port = NETFONE_COMMAND_PORT;
	    }
	    *NewHostParams.port_no = (unsigned short) port;
	    	
	    //  Check to see if it is a dotted IP address
	
	    NewHostParams.laddr = inet_addr(NewHostParams.pszHostName);
	
	    if (NewHostParams.laddr == INADDR_NONE) {
	
	        //  Assume the user gave us an actual host name
	
	        hAsyncTask = WSAAsyncGetHostByName(hwnd, WM_SOCKET_ASYNC,
							NewHostParams.pszHostName, NewHostParams.bBuffer,
							sizeof(NewHostParams.bBuffer));
	    } else {
	
	        //  The user gave us a dotted IP address
	        
	        if (!waNetSynchronousGetHostnameAction) {
		        hAsyncTask = WSAAsyncGetHostByAddr(hwnd, WM_SOCKET_ASYNC,
		              			(CHAR *) &NewHostParams.laddr,
		              			sizeof(NewHostParams.laddr), PF_INET,
		              			NewHostParams.bBuffer, sizeof(NewHostParams.bBuffer));
		    } else {
		    	int serr;
			    LPHOSTENT h = gethostbyaddr((CHAR *) (CHAR *) &NewHostParams.laddr,
			                                 sizeof(NewHostParams.laddr),
			                                 PF_INET);
		      	serr = (h == NULL) ?  WSAGetLastError() : 0;
		      	if (h != NULL) {
		      		memcpy(NewHostParams.bBuffer, h, sizeof(NewHostParams.bBuffer)); 
		      	}
		      	NewHost_OnSocketAsync(hwnd, 0, serr, (SOCKEVENT) 0);
		      	return;
	    	}
	    }
	
	    if (hAsyncTask == NULL) {
	
	        //  Could not initiate the asynchronous API
	
	        serr = WSAGetLastError();
	        MsgBox(hwnd, MB_ICONSTOP | MB_OK, Format(40),
	                NewHostParams.pszHostName, serr, SockerrToString(serr));
	        return;
	    }
	
	    /*  The async command has been issued.  Disable all dialog
	        controls except [Cancel]. */
	
	    NewHost_EnableControls(hwnd, FALSE);
	}
}

/*	NEWHOST_DLGPROC  --  New host dialogue procedure.  */

BOOL CALLBACK NewHost_DlgProc(HWND hwnd, UINT nMessage, WPARAM wParam,
                               LPARAM lParam)
{
    switch (nMessage) {
    
    	case WM_INITDIALOG:
    		Edit_LimitText(GetDlgItem(hwnd, IDD_NEW_HOST), MAX_HOST);
#ifdef MODEM    		
    		EnableWindow(GetDlgItem(hwnd, IDC_NEW_MODEM),
    			modemHandle != -1 && modemSessions == 0);
#else
			ShowWindow(GetDlgItem(hwnd, IDC_NEW_MODEM), SW_HIDE);    			
#endif    			
    		ShowWindow(GetDlgItem(hwnd, IDD_NEW_HOST_NAME), SW_SHOW);
    		ShowWindow(GetDlgItem(hwnd, IDD_NEW_HOST_DIAL_STRING), SW_HIDE);
    		break;
    		
    	case WM_COMMAND:
    		NewHost_OnCommand(hwnd, (short) WM_COMMAND_ID(wParam), (HWND) (UINT) lParam,
    			(UINT) WM_COMMAND_NOTIFY);  
    		break;
    		
    	case WM_SOCKET_ASYNC:
    		NewHost_OnSocketAsync(hwnd, (SOCKET) (wParam),
    			(SOCKERR) WSAGETSELECTERROR(lParam),
    			(SOCKEVENT) WSAGETSELECTEVENT(lParam));
    		break;
    }
    return FALSE;
}

/*	NEWHOSTDIALOGUE  --  Open a new connection to a given host name or
						 IP number.  */

BOOL newHostDialogue(HWND hwndParent, LPSTR pszHostName, LPIN_ADDR paddr,
					 unsigned short *port)
{
    BOOL fResult;

    //  Setup dialog parameters

    memset(&NewHostParams, 0, sizeof(NewHostParams));

    NewHostParams.pszHostName = pszHostName;
    NewHostParams.paddr = paddr;
    NewHostParams.hAsync = NULL;
    NewHostParams.port_no = port;
	    
    //  Invoke the dialogue
	
    fResult = DialogBox(hInst, IDD_NEW, hwndParent, NewHost_DlgProc);
    return fResult;
}

//	VOX Monitor dialogue handler

static HWND hDlgVoxMonitor = NULL;
static long nCurrentAudioLevel = 0;
static long nCurrentVoxLevel = 0;
static int PrevNoiseThreshold = 0;

static void PaintLevel(HWND hCtrl, int bPaint)
{
  	HDC hdc;
  	RECT rect;
  	HBRUSH hbrush, hbrush2;
  	int len, NewTop, VoxTop;
  	double val, scl;
    static int OldTop = 0;
    static int OldVox = 0;
    static int RecLevel = 0;
    if (RecLevel++ > 0) {
    	--RecLevel;
    	return;
    }
  	if (bPaint) {
  		InvalidateRect(hCtrl, NULL, TRUE);
  		UpdateWindow(hCtrl);
  	}
  	hdc = GetDC(hCtrl);
  	GetClientRect(hCtrl, &rect);
  	scl = log(32767.0);
  	
  	//	Paint the green bar showing the current audio level
  	
  	if (nCurrentAudioLevel > 0) {
      val = log((double) nCurrentAudioLevel);
    } else {
      val = 0;
    }
  	len = rect.bottom - rect.top;
  	NewTop = len - (int) ((val * len) / scl);
  	hbrush = CreateSolidBrush(RGB(0, 255 ,0));
  	if (!bPaint) {
  		if (NewTop > OldTop) {
  			rect.bottom = NewTop;
  			rect.top = OldTop;
	  		FillRect(hdc, &rect, GetStockObject(WHITE_BRUSH));
  		} else {
  			rect.bottom = OldTop;
  			rect.top = NewTop;
	  		FillRect(hdc, &rect, hbrush);
	  	}
    } else {
  		FillRect(hdc, &rect, GetStockObject(WHITE_BRUSH));
  		rect.top = NewTop;
  		FillRect(hdc, &rect, hbrush);
    }
  	OldTop = NewTop;
  	
  	//	Paint the red bar showing the VOX level
  	
  	hbrush2 = CreateSolidBrush(RGB(255,0,0));
	VoxTop =  1 + (int) (((double) noise_threshold * (len - 1)) / 1000.0);
	if (!bPaint && (OldVox != VoxTop)) {
		rect.top = OldVox;
		rect.bottom = rect.top - 1;
		if (OldVox > NewTop) {
			FillRect(hdc, &rect, hbrush);
		} else {
	  		FillRect(hdc, &rect, GetStockObject(WHITE_BRUSH));
	  	}
	}
  	rect.top = VoxTop;
	rect.bottom = rect.top - 1;
	FillRect(hdc, &rect, hbrush2);
	OldVox = VoxTop;
  	DeleteObject(hbrush2);
  	DeleteObject(hbrush);
  	ReleaseDC(hCtrl, hdc);
    --RecLevel;
}

static void UpdateScroll(HWND hwnd)
{
	char sNum[16];
	double v;
	
  	if (PrevNoiseThreshold != noise_threshold) {
		SetScrollPos(GetDlgItem(hwnd, IDC_VOX_SENSITIVITY), SB_CTL, noise_threshold, TRUE);
		v = 100.0 - ((double) noise_threshold / 10.0);
		sprintf(sNum, "%2.2lf", v);
		SetDlgItemText(hwnd, IDC_VOX_SHOW, sNum);
  		PrevNoiseThreshold = noise_threshold;
	}
}

BOOL CALLBACK voxMonitor_DlgProc(HWND hwnd, UINT nMessage, WPARAM wParam, LPARAM lParam)
{
    switch (nMessage) {
    	case WM_INITDIALOG:
	    	{
	    		SetScrollRange(GetDlgItem(hwnd, IDC_VOX_SENSITIVITY), SB_CTL, 0, 1000, TRUE);
	    	  	nCurrentAudioLevel = 0;
  				PrevNoiseThreshold = noise_threshold - 1;
	    	  	UpdateScroll(hwnd);
	    	}
	    	return TRUE;
	    	
	    case WM_CLOSE:
	    	DestroyWindow(hwnd);
	    	return TRUE;
	    
	    case WM_VSCROLL:
		    switch (LOWORD(wParam)) {
		    	case SB_BOTTOM:
		    		noise_threshold = 0;
		    		break;
		    	case SB_TOP:
		    		noise_threshold = 1000;
		    		break;
		    	case SB_LINEUP:
		    		noise_threshold -= 10;
		    		break;
		    	case SB_LINEDOWN:
		    		noise_threshold += 10;
		    		break;
		    	case SB_PAGEUP:
		    		noise_threshold -= 100;
		    		break;
		    	case SB_PAGEDOWN:
		    		noise_threshold += 100;
		    		break;
		    	case SB_THUMBTRACK:
		    	case SB_THUMBPOSITION:
		    		noise_threshold = HIWORD(wParam);
		    		break;
		    }
		    if (noise_threshold < 0) {
		    	noise_threshold = 0;
		    } else if (noise_threshold > 1000) {
		    	noise_threshold = 1000;
		    }
	    	UpdateScroll(hwnd);
	    	if (!inputActive) {
	    		PaintLevel(GetDlgItem(hwnd, IDC_VOX_LEVEL), 1);
	    	}
		    return TRUE;

        case WM_COMMAND:
		    switch ((short) WM_COMMAND_ID(wParam)) {
		    	case IDOK:
		        	PostMessage(hwnd, WM_CLOSE, 0, 0L);
		        	break;
		        	
                case ID_HELP:
                	displayHelpTopic(IDS_HELP_VOX);
                	break;
		    }
        	return TRUE;
        
        case WM_PAINT:
        	PaintLevel(GetDlgItem(hwnd, IDC_VOX_LEVEL), TRUE);
        	return FALSE;

	    case WM_DESTROY:
	    	hDlgVoxMonitor = NULL;
	    	return FALSE;
    }
    return FALSE;
}

BOOL voxMonitorDialog(HWND hwndParent)
{
    if (hDlgVoxMonitor != NULL) {
    	return FALSE;
    }
    hDlgVoxMonitor = CreateDialog(hInst, MAKEINTRESOURCE(IDD_VOX), hwndParent, voxMonitor_DlgProc);
    return TRUE;
}

BOOL IsVoxMonitorMessage(MSG *pmsg)
{
    if (!hDlgVoxMonitor) {
    	return FALSE;
    }
    return IsDialogMessage(hDlgVoxMonitor, pmsg);
}

void voxMonitorUpdate(long nAudio, long nVox)
{
  	if (!hDlgVoxMonitor) {
   		return;
   	}
  	nCurrentAudioLevel = nAudio;
  	nCurrentVoxLevel = nVox;
    PaintLevel(GetDlgItem(hDlgVoxMonitor, IDC_VOX_LEVEL), 0);
    UpdateScroll(hDlgVoxMonitor);
}

BOOL IsVoxMonitorOn()
{
    return (hDlgVoxMonitor != NULL);
}

⌨️ 快捷键说明

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