VCTERM Sample: Uses the Microsoft Communications ActiveX Control
TOC
Collapse the table of content
Expand the table of content
This documentation is archived and is not being maintained.

VCTERM Sample: Uses the Microsoft Communications ActiveX Control

Visual Studio .NET 2003

The VCTERM sample is a simple terminal emulation program illustrating the use of the Mscomm32.ocx ActiveX control. It illustrates how to use the Communications control with a serial port. The Communications control allows you to open a serial port, change its settings, send and receive data through the port, and monitor and set many of the different data lines.

This sample does not use the document/view architecture of the Microsoft Foundation Classes. The initial application was generated with the application wizard as an MFC SDI-type application, but the document and view classes were then removed because they are not needed.

The Mscomm32.ocx ActiveX control is created dynamically at runtime as a data member of the CMainFrame class. The creation code is located in the CMainFrame::OnCreate function.

An edit control is parented off of the CMainFrame window and is the interface for displaying the text that is sent and received through the Mscomm32.ocx control. The edit control is resized by overriding CMainFrame::RecalcLayout.

This sample also illustrates how to create a modeless status dialog box capable of canceling an operation. The CCancelDlg class is a modeless dialog box class, and simply signals the CMainFrame to stop transmitting data. The interesting code is in the CMainFrame::OnFileTransmit function. Note the calls to the DoEvents function, which processes all pending messages in the application's message queue.

Building and Running the Sample

To build and run the VCTERM sample

  1. Open the solution vcterm.sln.
  2. On the Build menu, click Build.
  3. On the Debug menu, click Start Without Debugging.

You will need to have either a modem attached to your computer's serial port or have two computers connected through a null-modem cable. Some modem commands that are hardcoded into this sample might not work with some modems. There are notes in the source code to point out where modem commands might need to be modified to work with a particular modem. Please consult the documentation included with your modem to determine the appropriate command strings to send to your modem.

After you have connected a null-modem cable to your computers, simply build and run the sample. Select the desired port settings (settings should be identical across both machines) and open the port. At this point, text typed into the edit window of the VCTERM application should appear in the Edit window of the VCTERM application running on the other machine.

Note   This sample does not support downloading files. It also does not support transmitting binary files. VCTERM supports transmitting ASCII text only.
Note   Some samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.

See Also

MFC Samples

Show:
© 2016 Microsoft