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

📄 mgt.cpp

📁 通过VC源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	CDialog::OnOK();
}

void CSimulatorDlg::OnClear() 
{
 	c_Trace.ResetContent();	
	updateControls(FALSE);
}

/****************************************************************************
*                         CSimulatorDlg::OnClearInput
* Result: void
*       
* Effect: 
*       Clears the input buffer.  This will force an ERR condition if there
*	is an attempt to read the rest of the packet before a new one is
*	established
****************************************************************************/

void CSimulatorDlg::OnClearInput() 
{
 	input = _T("");
	c_Transfer.SetWindowText(_T(""));
	err = TRUE;

	updateControls(FALSE);
}

/****************************************************************************
*                         CSimulatorDlg::setTransfer
* Inputs:
*       CString & s: string that will be the new input data string
* Result: void
*       
* Effect: 
*       Transfers the string to the input buffer and the display
****************************************************************************/

void CSimulatorDlg::setTransfer(CString & s)
    {
     TraceItem * item = new TraceItem(TRACE_TYPE_SEND, s);
     c_Trace.AddString(item);

     c_Transfer.SetWindowText(s);
     input = s;
    }

/****************************************************************************
*                            CSimulatorDlg::OnSend
* Result: void
*       
* Effect: 
*       Initiates the transfer of the currently set string
* Notes:
*	In manual mode, this initiates the transfer of the next character of
*	the string, with automatic EOP handling
*	In freerun mode, simply initiates the process of sending
****************************************************************************/

void CSimulatorDlg::OnSend() 
    {
     CString s;
     c_Data.GetWindowText(s);
     int n = c_Data.FindStringExact(-1, s);
     if(n == CB_ERR)
	{ /* add it */
	 n = c_Data.AddString(s);
	 c_Data.SetCurSel(n);
	} /* add it */
     else
	{ /* already exists */
	 c_Data.SetCurSel(n);
	} /* already exists */


     if(c_Manual.GetCheck())
	{ /* manual */
	 // If this is the first time we've used the Send, we transfer the
	 // data from the combo box to the input buffer.  
	 // We determine this by checking to see if the input buffer is
	 // empty
	 if(c_Transfer.GetWindowTextLength() == 0)
	    { /* first time */
	     setTransfer(s);
	    } /* first time */
	 OpenRegisterTransaction(_T("OnSend"));
	 sendNext();
	 CloseRegisterTransaction(_T("OnSend"));
	} /* manual */
     else
        { /* free run */
	 setTransfer(s);
	} /* free run */

     err = FALSE; // clear aborted-packet error flag

     updateControls(FALSE);
    }

void CSimulatorDlg::OnSelendokData() 
{
    updateControls(FALSE);
}

void CSimulatorDlg::OnClose() 
{
 	if(!manual)
	   OnManual(); // force into manual mode so shutdown works

	CDialog::OnClose();
}

void CSimulatorDlg::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
 	// Now resize the list box

	if(c_Trace.m_hWnd == NULL)
	    return; // startup transient
 	CRect lb;
	c_Trace.GetWindowRect(&lb);
	
	CRect dlg;
	GetWindowRect(&dlg);

	int border = lb.left - dlg.left;

	lb.right = dlg.right - border; 
	lb.bottom = dlg.bottom - border;

	if(lb.bottom <= lb.top)
	   return; // negative size

	ScreenToClient(&lb);
	c_Trace.SetWindowPos(NULL, 0, 0, lb.Width(), lb.Height(), 
					SWP_NOMOVE | SWP_NOZORDER);
	
	
}

void CSimulatorDlg::OnGetMinMaxInfo(MINMAXINFO FAR* MMI) 
{
 CDialog::OnGetMinMaxInfo(MMI);

 if(c_OK.m_hWnd == NULL)
     return;	// startup transient

 CRect r;
 c_OK.GetWindowRect(&r);

 CRect trace;
 c_Trace.GetWindowRect(&trace);
 CRect dlg;
 GetWindowRect(&dlg);

 int border = trace.left - dlg.left;

 MMI->ptMinTrackSize.x = r.right + border;
 MMI->ptMinTrackSize.y = trace.top + 20;
}

void CSimulatorDlg::OnGenerate() 
{
 CString s;
 buzzphrase(s);
 c_Data.SetWindowText(s);	
 updateControls(FALSE);
}

void CSimulatorDlg::OnEditchangeData() 
{
 updateControls(FALSE);	
}

/****************************************************************************
*                           CSimulatorDlg::shutdown
* Result: void
*       
* Effect: 
*       Shuts down the polling thread
****************************************************************************/

void CSimulatorDlg::shutdown()
    {
     if(pollthread != NULL)
	{ /* shut down polling */
	 // Note that because the pollthread object is destroyed when
	 // the thread terminates, we have to save the actual handle
	 // so we can wait on it (we could inhibit the object destruction
	 // but choose to do it this way instead)
	 HANDLE thread = pollthread->m_hThread;
	 polling = FALSE;
	 ::SetEvent(freerun); // if the state was manual, force it to run
	 ::SetEvent(pause);   // if it was paused, let it proceed
	 WaitForSingleObject(thread, INFINITE);

	 CloseHandle(freerun);
	} /* shut down polling */
    }

/****************************************************************************
*                         CSimulatorDlg::optimizedSet
* Inputs:
*       CButton & ctl: Control to be set
*	BYTE value: Value to be used to set it (as a bit mask)
*	BYTE mask:  Mask used to determine the selected bit
* Result: void
*       
* Effect: 
*       Sets the check box.  If the check box is already in the desired
*	state, does not set it (reduces flicker)
****************************************************************************/

void CSimulatorDlg::optimizedSet(CButton & ctl, BYTE value, BYTE mask)
    {
     BOOL desired = (value & mask) != 0;
     BOOL control = ctl.GetCheck() == BST_CHECKED;
     if(desired ^ control)
        { /* changed */
	 ctl.SetCheck(desired ? BST_CHECKED : BST_UNCHECKED);
	} /* changed */

    }

/****************************************************************************
*                     CSimulatorDlg::InCommandToControls
* Inputs:
*       BYTE command: Command register as read from device
* Result: void
*       
* Effect: 
*       Sets the state of the controls from the command byte
* Notes:
*	Optimizes update to reduce flicker
****************************************************************************/

void CSimulatorDlg::InCommandToControls(BYTE command)
    {
     optimizedSet(c_IEIn,   command, REGISTER_IN_COMMAND_IE);
     optimizedSet(c_GoIn,   command, REGISTER_IN_COMMAND_GO);
     optimizedSet(c_IACKIn, command, REGISTER_IN_COMMAND_IACK);
     optimizedSet(c_RSTIn,  command, REGISTER_IN_COMMAND_RST);
    }

/****************************************************************************
*                     CSimulatorDlg::InControlsToCommand
* Result: BYTE
*       Command bits as seen in the controls
****************************************************************************/

BYTE CSimulatorDlg::InControlsToCommand()
    {
     BYTE result = 0;
     if(c_GoIn.GetCheck() == BST_CHECKED)
	result |= REGISTER_IN_COMMAND_GO;
     if(c_IEIn.GetCheck() == BST_CHECKED)
	result |= REGISTER_IN_COMMAND_IE;
     if(c_IACKIn.GetCheck() == BST_CHECKED)
	result |= REGISTER_IN_COMMAND_IACK;
     if(c_RSTIn.GetCheck() == BST_CHECKED)
	result |= REGISTER_IN_COMMAND_RST;
     return result;
    }

/****************************************************************************
*                     CSimulatorDlg::OutCommandToControls
* Inputs:
*       BYTE command: Command register as read from device
* Result: void
*       
* Effect: 
*       Sets the state of the controls from the command byte
* Notes:
*	Optimizes update to reduce flicker
****************************************************************************/

void CSimulatorDlg::OutCommandToControls(BYTE command)
    {
     optimizedSet(c_IEOut,   command, REGISTER_OUT_COMMAND_IE);
     optimizedSet(c_GoOut,   command, REGISTER_OUT_COMMAND_GO);
     optimizedSet(c_IACKOut, command, REGISTER_OUT_COMMAND_IACK);
     optimizedSet(c_RSTOut,  command, REGISTER_OUT_COMMAND_RST);
    }

/****************************************************************************
*                     CSimulatorDlg::OutControlsToCommand
* Result: BYTE
*       Command bits as seen in the controls
****************************************************************************/

BYTE CSimulatorDlg::OutControlsToCommand()
    {
     BYTE result = 0;
     if(c_GoOut.GetCheck() == BST_CHECKED)
	result |= REGISTER_OUT_COMMAND_GO;
     if(c_IEOut.GetCheck() == BST_CHECKED)
	result |= REGISTER_OUT_COMMAND_IE;
     if(c_IACKOut.GetCheck() == BST_CHECKED)
	result |= REGISTER_OUT_COMMAND_IACK;
     if(c_RSTOut.GetCheck() == BST_CHECKED)
	result |= REGISTER_OUT_COMMAND_RST;
     return result;
    }

/****************************************************************************
*                      CSimulatorDlg::InStatusToControls
* Inputs:
*       BYTE status: Status byte
* Result: void
*       
* Effect: 
*       Sets the state of the controls to the input status flags
* Notes:
*	Uses optimized update to reduce flicker
****************************************************************************/

void CSimulatorDlg::InStatusToControls(BYTE status)
    {
     optimizedSet(c_ErrIn, status, REGISTER_IN_STATUS_ERR );
     optimizedSet(c_OvrIn, status, REGISTER_IN_STATUS_OVR );
     optimizedSet(c_EopIn, status, REGISTER_IN_STATUS_EOP );
     optimizedSet(c_IntIn, status, REGISTER_IN_STATUS_INT );
     optimizedSet(c_DoneIn,status, REGISTER_IN_STATUS_DONE);
     updateControls(FALSE); // handle any induced dependencies
    }

/****************************************************************************
*                      CSimulatorDlg::InControlsToStatus
* Result: BYTE
*       A status byte representing the current state in the controls
****************************************************************************/

BYTE CSimulatorDlg::InControlsToStatus()
    {
     BYTE result = 0;
     if(c_ErrIn.GetCheck() == BST_CHECKED)
	result |= REGISTER_IN_STATUS_ERR;
     if(c_OvrIn.GetCheck() == BST_CHECKED)
	result |= REGISTER_IN_STATUS_OVR;
     if(c_EopIn.GetCheck() == BST_CHECKED)
	result |= REGISTER_IN_STATUS_EOP;
     if(c_IntIn.GetCheck() == BST_CHECKED)
	result |= REGISTER_IN_STATUS_INT;
     if(c_DoneIn.GetCheck() == BST_CHECKED)
	result |= REGISTER_IN_STATUS_DONE;
     return result;
    }

/****************************************************************************
*                      CSimulatorDlg::OutStatusToControls

⌨️ 快捷键说明

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