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

📄 settings.c

📁 用于串口的测试调试
💻 C
📖 第 1 页 / 共 3 页
字号:
    char szBuffer[ MAXLEN_TEMPSTR ], szTemp[ MAXLEN_TEMPSTR ] ;
    WORD wCount, wMaxCOM, wPosition ;

    wMaxCOM = MAXPORTS ;
    strcpy(szTemp, "COM");

    //
    // fill port combo box and make initial selection
    //
    for (wCount = 0; wCount < wMaxCOM; wCount++) {
	wsprintf( szBuffer, "%s%d", (LPSTR) szTemp, wCount + 1 ) ;
	SendDlgItemMessage( hDlg, IDC_PORTCOMBO, CB_ADDSTRING, 0,
			    (LPARAM) (LPSTR) szBuffer ) ;
    }

    SendDlgItemMessage( hDlg, IDC_PORTCOMBO, CB_SETCURSEL,
		       (WPARAM) (PORT( TTYInfo ) - 1), 0L ) ;
   
    GetDlgItemText(hDlg, IDC_PORTCOMBO, gszPort, sizeof(gszPort));

    //
    // fill baud combo box and make initial selection
    //
    FillComboBox( GetDlgItem( hDlg, IDC_BAUDCOMBO ),
		  szBaud, BaudTable,
		  sizeof( BaudTable ) / sizeof( BaudTable[ 0 ] ),
		  BAUDRATE( TTYInfo ) ) ;

    //
    // fill data bits combo box and make initial selection
    //
    for (wCount = 5; wCount < 9; wCount++) {
	wsprintf( szBuffer, "%d", wCount ) ;
	wPosition = LOWORD( SendDlgItemMessage( hDlg, IDC_DATABITSCOMBO,
						CB_ADDSTRING, 0,
						(LPARAM) (LPSTR) szBuffer ) ) ;

	//
	// if wCount is current selection, tell the combo box
	//
	if (wCount == BYTESIZE( TTYInfo ))
	    SendDlgItemMessage( hDlg, IDC_DATABITSCOMBO, CB_SETCURSEL,
				(WPARAM) wPosition, 0L ) ;
    }

    //
    // fill parity combo box and make initial selection
    //
    FillComboBox(   GetDlgItem( hDlg, IDC_PARITYCOMBO ),
		    szParity, ParityTable,
		    sizeof( ParityTable ) / sizeof( ParityTable[ 0 ] ),
		    PARITY( TTYInfo ) ) ;

    //
    // fill stop bits combo box and make initial selection
    //
    FillComboBox(   GetDlgItem( hDlg, IDC_STOPBITSCOMBO ),
		    szStopBits, StopBitsTable,
		    sizeof( StopBitsTable ) / sizeof ( StopBitsTable[ 0 ] ),
		    STOPBITS( TTYInfo ) ) ;
    //
    // set check marks based on TTY data
    //
    CheckDlgButton( hDlg, IDC_LOCALECHOCHK, LOCALECHO( TTYInfo ) ) ;
    CheckDlgButton( hDlg, IDC_DISPLAYERRORSCHK, DISPLAYERRORS( TTYInfo ) );
    CheckDlgButton( hDlg, IDC_LFBTN, NEWLINE( TTYInfo ) );
    CheckDlgButton( hDlg, IDC_AUTOWRAPCHK, AUTOWRAP( TTYInfo ) );

    CheckDlgButton( hDlg, IDC_NOWRITINGCHK, NOWRITING( TTYInfo ) );
    CheckDlgButton( hDlg, IDC_NOREADINGCHK, NOREADING( TTYInfo ) );
    CheckDlgButton( hDlg, IDC_NOSTATUSCHK,  NOSTATUS( TTYInfo ) );
    CheckDlgButton( hDlg, IDC_NOEVENTSCHK,  NOEVENTS( TTYInfo ) );

    return ( TRUE ) ;

} // end of SettingsDlgInit()


/*-----------------------------------------------------------------------------

FUNCTION: GetdwTTYItem(HWND, int, char **, DWORD *, int)

PURPOSE: Returns a DWORD item from a dialog control

PARAMETERS:
    hDlg      - Dialog window handle
    idControl - id of control to get data from
    szString  - table of strings that the control displays
    pTable    - table of data associated with strings
    iNumItems - size of table

RETURN:  
    DWORD item corresponding to control selection
    0 if item not found correctly

HISTORY:   Date:      Author:     Comment:
	   10/27/95   AllenD      Wrote it

-----------------------------------------------------------------------------*/
DWORD GetdwTTYItem(HWND hDlg, int idControl, char ** szString, DWORD * pTable, int iNumItems)
{
    int i;
    char szItem[MAXLEN_TEMPSTR];

    //
    // Get current selection (a string)
    //
    GetDlgItemText(hDlg, idControl, szItem, sizeof(szItem));
    
    /*
	Compare current selection with table to find index of item.
	If index is found, then return the DWORD item from table.
    */ 
    for (i = 0; i < iNumItems; i++) {
	if (strcmp(szString[i], szItem) == 0)
	    return pTable[i];
    }

    return 0;
}

/*-----------------------------------------------------------------------------

FUNCTION: GetbTTYItem(HWND, int, char **, DWORD *, int)

PURPOSE: Returns a BYTE item from a dialog control

PARAMETERS:
    hDlg      - Dialog window handle
    idControl - id of control to get data from
    szString  - table of strings that the control displays
    pTable    - table of data associated with strings
    iNumItems - size of table

RETURN:
    BYTE item from corresponding to control selection 
    0 if item data not found

HISTORY:   Date:      Author:     Comment:
	   10/27/95   AllenD      Wrote it

-----------------------------------------------------------------------------*/
BYTE GetbTTYItem(HWND hDlg, int idControl, char ** szString, DWORD * pTable, int iNumItems)
{
    int i;
    char szItem[MAXLEN_TEMPSTR];

    //
    // Get current selection (a string)
    //
    GetDlgItemText(hDlg, idControl, szItem, sizeof(szItem));
    
    /*
	Compare current selection with table to find index of item.
	If index is found, then return the BYTE item from table.
    */ 
    for (i = 0; i < iNumItems; i++) {
	if (strcmp(szString[i], szItem) == 0)
	    return (BYTE) pTable[i];
    }
    
    return 0;
}


/*-----------------------------------------------------------------------------

FUNCTION: ToolbarProc(HWND, UINT, WPARAM, LPARAM)

PURPOSE: Dialog Procedure for Settings Dialog

PARAMETERS:
    hWndDlg - Dialog window handle
    uMsg    - Window message
    wParam  - message parameter (depends on message)
    lParam  - message parameter (depends on message)

RETURN:
    TRUE if message is handled
    FALSE if message is not handled
    Exception is WM_INITDIALOG: returns FALSE since focus is not set

HISTORY:   Date:      Author:     Comment:
	   10/27/95   AllenD      Wrote it

-----------------------------------------------------------------------------*/
BOOL CALLBACK ToolbarProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    BOOL fRet = FALSE;

    switch(uMsg)
    {
	case WM_INITDIALOG:     // setup dialog with defaults
	    SettingsDlgInit(hWndDlg);
	    break;

	case WM_COMMAND: 
	    {
		switch(LOWORD(wParam))
		{
		    case IDC_FONTBTN:       // font button pressed
			{
			    CHOOSEFONT cf = {0};
			    LOGFONT lf;

			    lf = LFTTYFONT(TTYInfo);
			    cf.lStructSize = sizeof(CHOOSEFONT);
			    cf.hwndOwner = hWndDlg;
			    cf.lpLogFont = &lf;
			    cf.rgbColors = FGCOLOR(TTYInfo);
			    cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS | CF_FIXEDPITCHONLY | \
				       CF_EFFECTS;

			    if (!ChooseFont(&cf))
				break;

			    InitNewFont(lf, cf.rgbColors);

			    //
			    // fix scroll bar sizes since we may have more or less pixels per
			    // character now
			    //
			    SizeTTY(ghWndTTY, (WORD)XSIZE(TTYInfo), (WORD)YSIZE(TTYInfo));
			    
			    //
			    // repaint screen contents
			    //
			    InvalidateRect(ghWndTTY, NULL, TRUE);
			    
			    //
			    // kill old cursor
			    //
			    KillTTYFocus(ghWndTTY);
			    
			    //
			    // create new cursor
			    //
			    SetTTYFocus(ghWndTTY);
			}
			fRet = FALSE;
			break;

		    case IDC_COMMEVENTSBTN:     // comm events button pressed
			DialogBox(ghInst, MAKEINTRESOURCE(IDD_COMMEVENTSDLG), ghwndMain, CommEventsProc);
			fRet = FALSE;
			break;

		    case IDC_FLOWCONTROLBTN:
			DialogBox(ghInst, MAKEINTRESOURCE(IDD_FLOWCONTROLDLG), ghwndMain, FlowControlProc);
			fRet = FALSE;
			break;

		    case IDC_TIMEOUTSBTN:
			DialogBox(ghInst, MAKEINTRESOURCE(IDD_TIMEOUTSDLG), ghwndMain, TimeoutsProc);
			fRet = FALSE;
			break;

		    default:                    // some other control has been modified
			if (CONNECTED(TTYInfo))
			    UpdateTTYInfo();
			break;
		}
	    }
	    break;

	default:
	    break;
    }    

    return fRet;
}

/*-----------------------------------------------------------------------------

FUNCTION: InitHexControl(HWND, WORD, WORD, char)

PURPOSE: Places byte value into two edit boxes of the dialog

PARAMETERS:
    hdlg         - Dialog Handle
    wIdNumberBox - Edit control ID ; displays hex
    wIdCharBox   - Edit control ID ; displays char
    chData       - data to display

COMMENTS: Some dialogs may have an edit control designed to accept
	  hexidecimal input from the user.  This function initializes
	  such edit controls.  First, the byte (char) is placed into a
	  zero terminated string.  This is set as the item text of one
	  of the controls.  Next, the byte is converted to a hexidecimal
	  string.  This is set as the item text of the other control.

HISTORY:   Date:      Author:     Comment:
	   10/27/95   AllenD      Wrote it

-----------------------------------------------------------------------------*/
void InitHexControl(HWND hdlg, WORD wIdNumberBox, WORD wIdCharBox, char chData)
{
    char szFlagText[3] = {0};
    char szFlagChar[2] = {0};
    
    //
    // put character into char edit display control
    //
    szFlagChar[0] = chData;
    SetDlgItemText(hdlg, wIdCharBox, szFlagChar);
    
    //
    // put flag character into hex numeric edit control
    //
    wsprintf(szFlagText, "%02x", 0x000000FF & chData);
    SetDlgItemText(hdlg, wIdNumberBox, szFlagText);

    return;
}

/*-----------------------------------------------------------------------------

FUNCTION: GetHexControl(HWND, WORD, WORD)

PURPOSE: Get hex data from control and convert to character

PARAMETERS:
    hdlg         - Dialog Handle
    wIdNumberBox - Edit control ID ; contains hex string
    wIdCharBox   - Edit control ID ; displays the char

RETURN:
    0 if can't get hex string from edit control
    byte value of hex string otherwise

COMMENTS: Function does the following:
	  1) Gets first two characters from edit control
	  2) Converts hex string to numeric value
	  3) Displays ascii char of numeric value
	  4) Returns numeric value

HISTORY:   Date:      Author:     Comment:
	   10/27/95   AllenD      Wrote it

-----------------------------------------------------------------------------*/
char GetHexControl(HWND hdlg, WORD wIdNumberBox, WORD wIdCharBox)
{
    UINT uFlagValue;
    char chFlagEntered[3] = {0};
    char chFlag[2] = {0};
    
    //
    // get numeric value from control
    //
    if (0 == GetDlgItemText(hdlg, wIdNumberBox, chFlagEntered, 3))
	return 0;

    sscanf(chFlagEntered, "%x", &uFlagValue);

    chFlag[0] = (char) uFlagValue;
    SetDlgItemText(hdlg, wIdCharBox, chFlag); // display character

    return chFlag[0];
}
    
/*-----------------------------------------------------------------------------

FUNCTION: InitCommEventsDlg(HWND, DWORD)

PURPOSE: Initializes Comm Event Dialog Control

PARAMETERS:
    hdlg         - Dialog window handle
    dwEventFlags - event flag to set controls to

COMMENTS: Since controls are checked based on the dwEventFlags parameter, 
	  it is easy to init control based on current settings, 
	  or default settings.

HISTORY:   Date:      Author:     Comment:
	   10/27/95   AllenD      Wrote it

-----------------------------------------------------------------------------*/
void InitCommEventsDlg(HWND hdlg, DWORD dwEventFlags)
{
    int i,j;

    for (i = IDC_EVBREAKBTN, j = 0; i <= IDC_EVTXEMPTYBTN; i++, j++)
	CheckDlgButton( hdlg, i, dwEventFlags & EventFlagsTable[j]) ;

    InitHexControl(hdlg, IDC_FLAGEDIT, IDC_FLAGCHAR, FLAGCHAR(TTYInfo));

    EnableWindow(GetDlgItem(hdlg, IDC_FLAGEDIT),  dwEventFlags & EV_RXFLAG);
    EnableWindow(GetDlgItem(hdlg, IDC_FLAGCHAR),  dwEventFlags & EV_RXFLAG);

    return;
}

/*-----------------------------------------------------------------------------

FUNCTION: SaveCommEventsDlg(HWND)

PURPOSE: Saves new Comm Events Flag

PARAMETERS:
    hdlg - Dialog window handle

COMMENTS: Builds a new flag based on current dialog control.
	  If the new flag differs from old, then new is updated.

HISTORY:   Date:      Author:     Comment:
	   10/27/95   AllenD      Wrote it

-----------------------------------------------------------------------------*/
void SaveCommEventsDlg(HWND hdlg)
{
    int i,j;
    DWORD dwNew = {0};
    char chNewFlag = '\0';
    BOOL fChangingRXFLAG;

    //
    // create a flag out of dialog selections
    //
    for (i = IDC_EVBREAKBTN, j = 0; i <= IDC_EVTXEMPTYBTN; i++, j++) {
	if (IsDlgButtonChecked(hdlg, i))
	    dwNew |= EventFlagsTable[j];
    }

    //
    // get current flag character from dialog
    //
    chNewFlag = GetHexControl(hdlg, IDC_FLAGEDIT, IDC_FLAGCHAR);
    fChangingRXFLAG = (EVENTFLAGS(TTYInfo) & EV_RXFLAG) != (dwNew & EV_RXFLAG);
    if (chNewFlag != FLAGCHAR(TTYInfo) || fChangingRXFLAG) {
	FLAGCHAR(TTYInfo) = chNewFlag;
	UpdateTTYInfo();
    }

    //
    // if new flags have been selected, or
    //
    if (dwNew != EVENTFLAGS(TTYInfo))
	EVENTFLAGS(TTYInfo) = dwNew;

    return;
}

/*-----------------------------------------------------------------------------

FUNCTION: CommEventsProc(HWND, UINT, WPARAM, LPARAM)

PURPOSE: Dialog Procedure for Comm Events Dialog

PARAMETERS:
    hdlg     - Dialog window handle
    uMessage - window message
    wparam   - message parameter (depends on message)
    lparam   - message parameter (depends on message)

RETURN:
    TRUE if message is handled
    FALSE if message is not handled
    Exception is WM_INITDIALOG: returns FALSE since focus is not set

HISTORY:   Date:      Author:     Comment:
	   10/27/95   AllenD      Wrote it

-----------------------------------------------------------------------------*/
BOOL CALLBACK CommEventsProc(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
    switch(uMessage)
    {
	case WM_INITDIALOG:     // init controls
	    InitCommEventsDlg(hdlg, EVENTFLAGS(TTYInfo));
	    break;

	case WM_COMMAND: 
	    switch(LOWORD(wparam))

⌨️ 快捷键说明

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