home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
windows
/
winkerm.zip
/
WINCMD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1986-10-10
|
6KB
|
239 lines
/***************************************************************************
*
* wincmd.c
*
* Windows Kermit menu support module.
*
***************************************************************************/
#include <windows.h>
#include "winkrm.h"
/* These functions are local to this segment and so can be declared NEAR */
void NEAR SetBaud(WORD, HMENU);
void NEAR SetState(WORD, HMENU);
void NEAR SetSerial(WORD, HMENU);
void NEAR LoadDCB(void);
/***************************************************************************
*
* KerCommand
*
* Called from the window procedure when a WM_COMMAND message is received
*
* Entry: Handle to the Window,
* the command paramter,
* the lParam passed to the Windows procedure.
*
* Exit: Command executed
*
***************************************************************************/
KerCommand(hWnd,cmd,lParam)
HWND hWnd;
WORD cmd;
LONG lParam;
{
HMENU hMenu = GetMenu(hWnd); /* fetch the menu handle for later */
switch(cmd) {
case CONNECTSTATE: /* Set one of the three main states */
case RECEIVESTATE:
case SENDSTATE:
SetState(cmd, hMenu);
break;
case COMMPORT1: /* Switch or disable a port */
case COMMPORT2:
SetSerial(cmd,hMenu);
break;
case BAUD300: /* Set the baud rate */
case BAUD1200:
case BAUD2400:
SetBaud(cmd, hMenu);
break;
}
}
/***************************************************************************
*
* SetBaud
*
* Set the baud rate
*
* Entry: Command parameter,
* handle to the menu.
*
* Exit: Baud rate set.
*
* Notes: The baud rate is not changed if the rate asked for is alread set.
*
***************************************************************************/
void NEAR SetBaud(cmd, hMenu)
WORD cmd;
HMENU hMenu;
{
if (cmd != CurrentBaud) {
CheckMenuItem(hMenu, CurrentBaud, MF_UNCHECKED);
CurrentBaud = cmd;
switch (cmd) {
case BAUD300:
ComDCB.BaudRate = 300;
break;
case BAUD1200:
ComDCB.BaudRate = 1200;
break;
case BAUD2400:
ComDCB.BaudRate = 2400;
break;
}
SetCommState( (DCB FAR *)&ComDCB);
CheckMenuItem(hMenu, CurrentBaud, MF_CHECKED);
}
}
/***************************************************************************
*
* SetState
*
* Set the state of the program among the three possible states of
* Connect, Receive file, or Send file.
*
* Entry: Command word,
* handle to the menu.
*
* Exit: State selected or disabled.
*
***************************************************************************/
void NEAR SetState(cmd, hMenu)
WORD cmd;
HMENU hMenu;
{
/* In this case, just set things to no state */
if (cmd == CurrentState) {
CheckMenuItem(hMenu, CurrentState, MF_UNCHECKED);
CurrentState = 0;
}
/* Otherwise, gray out the old menu item, set the state, and check it */
else {
CheckMenuItem(hMenu, CurrentState, MF_UNCHECKED);
switch(cmd) {
case CONNECTSTATE:
CurrentState = CONNECTSTATE;
break;
case RECEIVESTATE:
CurrentState = RECEIVESTATE;
break;
case SENDSTATE:
CurrentState = SENDSTATE;
break;
}
CheckMenuItem(hMenu, CurrentState, MF_CHECKED);
}
}
/***************************************************************************
*
* SetSerial
*
* Select the active serial port
*
* Entry: Command word,
* handle to a menu.
*
* Exit: Port selected or deselected.
*
* Notes: The serial port parameters in the DCB control structure are
* initially set in the initialization module.
*
***************************************************************************/
void NEAR SetSerial(cmd,hMenu)
WORD cmd;
HMENU hMenu;
{
int result;
char *comdev = szCom1; /* has to be COM1 or COM2 */
char *errorstr = "Device Not Available";
if (cmd == COMMPORT2)
comdev = szCom2;
/* if cid < 0, then no port is open */
if (cid < 0) { /* try opening the device, return if not able */
result = OpenComm((LPSTR)comdev, RXBUFSIZE, TXBUFSIZE);
/*
We could try to respond to specific errors here. For example,
we might try reducing the size of the buffers if not enough
memory is available. Right now, we just abort the effort.
*/
if (result < 0) {
MessageBox(hKermWnd, (LPSTR)errorstr,
(LPSTR)comdev, MB_OK | MB_ICONEXCLAMATION);
return;
}
cid = result; /* handle to communications port */
CurrentPort = cmd;
LoadDCB(); /* load up the DCB structure */
CheckMenuItem(hMenu, CurrentPort, MF_CHECKED); /* fix up menus */
CheckMenuItem(hMenu, CurrentBaud, MF_CHECKED);
UnGrayMenuItems(hMenu); /* activate menus affected by com ports */
}
else {
/* in this case, toggle the port back off and fix up affected menus */
if (CurrentPort == cmd) {
CloseComm(cid);
CheckMenuItem(hMenu, CurrentPort, MF_UNCHECKED);
cid = MAXCOMMERR; /* cid < 0 again */
CurrentPort = 0;
GrayMenuItems(hKermWnd);
}
else {
/* In this case, toggle the other port on and this one off */
result = OpenComm((LPSTR)comdev, RXBUFSIZE, TXBUFSIZE);
if (result < 0) {
MessageBox(hKermWnd, (LPSTR)errorstr,
(LPSTR)comdev, MB_OK | MB_ICONEXCLAMATION);
return;
}
CloseComm(cid); /* close first port */
CheckMenuItem(hMenu, CurrentPort, MF_UNCHECKED); /* gray menu */
cid = result; /* set cid to the new handle */
CurrentPort = cmd; /* set up menu item parameter */
LoadDCB(); /* load up the port DCB */
CheckMenuItem(hMenu, CurrentPort, MF_CHECKED); /* activate menus */
CheckMenuItem(hMenu, CurrentBaud, MF_CHECKED);
UnGrayMenuItems(hMenu); /* ungray affected items */
}
}
}
/***************************************************************************
*
* LoadDCB
*
* Load the communications device control block and set our values
*
* Entry: None
*
* Exit: DCB loaded.
*
* Notes: The values for the DCB field are initialized in Winint.
*
***************************************************************************/
void NEAR LoadDCB()
{
DCB OldComDCB;
GetCommState(cid, (DCB FAR *)&OldComDCB);
ComDCB.Id = OldComDCB.Id;
SetCommState( (DCB FAR *)&ComDCB);
}