Category : C Source Code
Archive   : WINKERM.ZIP
Filename : KERMWND.C

 
Output of file : KERMWND.C contained in archive : WINKERM.ZIP
/*******************************************************************************
** **
** Kermit for Microsoft Windows **
** ---------------------------- **
** KERMWND.C **
** **
** This module contains the routines to handle the MS Windows housekeeping **
** that is required during a Kermit protocol. Includes a status window, **
** popup windows for messages, etc. **
** **
*******************************************************************************/

// INCLUDES -------------------------------------------------------------------

#include "kermit.h"
#include "kermprot.h"

//-----------------------------------------------------------------------------
VOID message(char *t, char *s)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
if (server)
tmsg("\n\r%s: %s", t, s);
else
MessageBox(hAppWnd, s, t, MB_OK | MB_ICONASTERISK);
}

//-----------------------------------------------------------------------------
VOID ShowRetries(int Retries)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
SetDlgItemInt(hXfrWnd, IDD_RETRIES, Retries, FALSE);
}

//-----------------------------------------------------------------------------
VOID ShowPackets(int Packets)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
SetDlgItemInt(hXfrWnd, IDD_PACKETS, Packets, FALSE);
}

//-----------------------------------------------------------------------------
VOID ShowBytes(long Bytes)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
char ByteStr[20];

if (filsiz > 0)
sprintf(ByteStr, "%li, %li%%", Bytes, (Bytes * 100) / filsiz);
else
sprintf(ByteStr, "%li", Bytes);

SetDlgItemText(hXfrWnd, IDD_BYTES, ByteStr);
}

//-----------------------------------------------------------------------------
VOID ShowTypeIn(char TypeIn)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
static char TypeStr[] = "\0\0";

TypeStr[0] = TypeIn;
SetDlgItemText(hXfrWnd, IDD_TYPEIN, TypeStr);
}

//-----------------------------------------------------------------------------
VOID ShowTypeOut(char TypeOut)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
static char TypeStr [] = "\0\0";

TypeStr[0] = TypeOut;
SetDlgItemText(hXfrWnd, IDD_TYPEOUT, TypeStr);
}

//-----------------------------------------------------------------------------
BOOL FAR PASCAL StatusDlgProc(HWND hDlg, unsigned message,
WORD wParam, LONG lParam)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
return (FALSE);
}

//-----------------------------------------------------------------------------
int GetSelCount(HWND hDlg, int nItem)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
int i, j, k;

j = (int)SendDlgItemMessage(hDlg, nItem, LB_GETCOUNT, 0, 0L);
k = 0;
for (i = 0; i < j; i++)
if (SendDlgItemMessage(hDlg, nItem, LB_GETSEL, i, 0L))
k++;

return(k);
}

//-----------------------------------------------------------------------------
long GetListText(HWND hDlg, int nItem, int nIndex, LPSTR lpString)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{

if (nIndex == -1) {
int i, j;

j = (int)SendDlgItemMessage(hDlg, nItem, LB_GETCOUNT, 0, 0L);
for (i = 0; i < j; i++)
if (SendDlgItemMessage(hDlg, nItem, LB_GETSEL, i, 0L)) {
nIndex = i;
break;
}
}

return(SendDlgItemMessage(hDlg, nItem, LB_GETTEXT, nIndex,
(LONG)(LPSTR)lpString));
}

//-----------------------------------------------------------------------------
VOID SendDlgAdd(HWND hDlg)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
WORD i, j;
BOOL bWild;
char szFileSpec[80];
OFSTRUCT OpenBuf;

GetDlgItemText(hDlg, IDD_FILE, szFileSpec, sizeof(szFileSpec));

// if a filespec was entered...
if (strlen(szFileSpec)) {
// if file exists add it and return
if (OpenFile(szFileSpec, &OpenBuf, OF_EXIST | OF_READ) != -1) {
SendDlgItemMessage(hDlg, IDD_SENDLIST, LB_INSERTSTRING,
-1, (LONG)(LPSTR)OpenBuf.szPathName);
SetDlgItemText(hDlg, IDD_FILE, "");
SetFocus(GetDlgItem(hDlg, IDD_FILE));
return;
}

// wildcards in filename???
bWild = FALSE;
for (i = 0; szFileSpec[i] != '\0'; i++)
if (szFileSpec[i] == '*' || szFileSpec[i] == '?')
bWild = TRUE;

// try to get the files, beep on error
if (!DlgDirList(hDlg, szFileSpec, IDD_FILELIST, IDD_CURDIR, 0)) {
SetFocus(GetDlgItem(hDlg, IDD_FILE));
MessageBeep(0);
return;
}

// if wildcards, add the files found
if (bWild && strlen(szFileSpec)) {
SetDlgItemText(hDlg, IDD_FILE, "");
SendDlgItemMessage(hDlg, IDD_FILELIST, LB_SETSEL, 1, -1L);
SendMessage(hDlg, WM_COMMAND, IDD_ADD, 0L);
}

// update the dir and file lists
szFileSpec[0] = '\0';
DlgDirList(hDlg, szFileSpec, IDD_DIRLIST, IDD_CURDIR, 0xC010);
DlgDirList(hDlg, szFileSpec, IDD_FILELIST, NULL, 0);
SetDlgItemText(hDlg, IDD_FILE, "");
SetFocus(GetDlgItem(hDlg, IDD_FILE));
return;
}

// no filespec, add selected list files
j = (WORD)SendDlgItemMessage(hDlg, IDD_FILELIST, LB_GETCOUNT, 0, 0L);
for (i = 0; i < j; i++)
if (SendDlgItemMessage(hDlg, IDD_FILELIST, LB_GETSEL, i, 0L)) {
SendDlgItemMessage(hDlg, IDD_FILELIST, LB_GETTEXT, i,
(LONG)(LPSTR)szFileSpec);
OpenFile(szFileSpec, &OpenBuf, OF_PARSE);
SendDlgItemMessage(hDlg, IDD_SENDLIST, LB_INSERTSTRING, -1,
(LONG)(LPSTR)OpenBuf.szPathName);
}
SendDlgItemMessage(hDlg, IDD_FILELIST, LB_SETSEL, 0, -1L);
}

//-----------------------------------------------------------------------------
VOID SendDlgRemove(HWND hDlg)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
WORD i, j;

for (i = j = 0; j != LB_ERR;) {
j = (int)SendDlgItemMessage(hDlg, IDD_SENDLIST, LB_GETSEL, i, 0L);
if (j && j != LB_ERR)
SendDlgItemMessage(hDlg, IDD_SENDLIST, LB_DELETESTRING, i, 0L);
else
i++;
}
}

//-----------------------------------------------------------------------------
BOOL SendDlgSend(HWND hDlg)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
char szFileSpec[80];

hSendList = CreateWindow("LISTBOX", "SendList", WS_CHILDWINDOW,
0, 0, 0, 0, hAppWnd, NULL, hAppInst, NULL);

if (!hSendList) {
MessageBeep(0);
return(FALSE);
}

while (SendDlgItemMessage(hDlg, IDD_SENDLIST, LB_GETTEXT,
0, (LONG)(LPSTR)szFileSpec) != LB_ERR) {
SendMessage(hSendList, LB_ADDSTRING, 0, (LONG)(LPSTR)szFileSpec);
SendDlgItemMessage(hDlg, IDD_SENDLIST, LB_DELETESTRING, 0, 0L);
}
}

//-----------------------------------------------------------------------------
BOOL FAR PASCAL SendDlgProc(HWND hDlg, unsigned message,
WORD wParam, LONG lParam)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
WORD i, j, k, l;
char szFileSpec[80];

switch (message) {
case WM_INITDIALOG:
szFileSpec[0] = '\0';
DlgDirList(hDlg, szFileSpec, IDD_DIRLIST, IDD_CURDIR, 0xC010);
DlgDirList(hDlg, szFileSpec, IDD_FILELIST, NULL, 0);
break;

case WM_COMMAND:
switch (wParam) {
case IDD_DIRLIST:
switch(HIWORD(lParam)) {
case LBN_DBLCLK:
SendMessage(hDlg, WM_COMMAND, IDD_ADD, 0L);
break;

case LBN_SELCHANGE:
if (DlgDirSelect(hDlg, szFileSpec, IDD_DIRLIST))
SetDlgItemText(hDlg, IDD_FILE, szFileSpec);
break;
}
break;

case IDD_FILELIST:
switch(HIWORD(lParam)) {
case LBN_DBLCLK:
SendMessage(hDlg, WM_COMMAND, IDD_ADD, 0L);
break;

case LBN_SELCHANGE:
break;

i = GetSelCount(hDlg, IDD_FILELIST);
WriteDebug(0, "SelCount=%i", i);

if (i < 1)
break;

szFileSpec[0] = '\0';
if (i == 1)
GetListText(hDlg, IDD_FILELIST,
-1, szFileSpec);
WriteDebug(0, "FileSpec=%s", szFileSpec);

SetDlgItemText(hDlg, IDD_FILE, szFileSpec);
break;
}
break;

case IDD_ADD:
SendDlgAdd(hDlg);
break;

case IDD_REMOVE:
SendDlgRemove(hDlg);
break;

case IDD_SEND:
SendDlgSend(hDlg);
EndDialog(hDlg, hSendList);
break;

case IDD_CANCEL:
EndDialog(hDlg, NULL);
break;

default:
return(FALSE);
}
default:
return(FALSE);
}
return(TRUE);
}

//-----------------------------------------------------------------------------
BOOL FAR PASCAL GetDlgProc(HWND hDlg, unsigned message,
WORD wParam, LONG lParam)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
switch (message) {
case WM_COMMAND:
switch (wParam) {
case IDD_OK:
GetDlgItemText(hDlg, IDD_PARMS, cmarg, 80);
EndDialog(hDlg, TRUE);
break;

case IDD_CANCEL:
EndDialog(hDlg, FALSE);
break;

default:
return(FALSE);
break;
}
break;

case WM_INITDIALOG:
SendDlgItemMessage (hDlg, IDD_PARMS, EM_LIMITTEXT, 79, 0L);
break;

default:
return(FALSE);
}
return(TRUE);
}

//-----------------------------------------------------------------------------
BOOL FAR PASCAL HostDlgProc(HWND hDlg, unsigned message,
WORD wParam, LONG lParam)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
switch (message) {
case WM_COMMAND:
switch (wParam) {
case IDD_OK:
GetDlgItemText(hDlg, IDD_PARMS, cmarg, 80);
EndDialog(hDlg, TRUE);
break;

case IDD_CANCEL:
EndDialog(hDlg, FALSE);
break;

default:
return(FALSE);
break;
}
break;

case WM_INITDIALOG:
SendDlgItemMessage(hDlg, IDD_PARMS, EM_LIMITTEXT, 79, 0L);
break;

default:
return(FALSE);
}
return(TRUE);
}

//-----------------------------------------------------------------------------
BOOL FAR PASCAL GenericDlgProc(HWND hDlg, unsigned message,
WORD wParam, LONG lParam)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
static char CommandTable[] = "ICLFDUETRKWMHQPJV";
static char CommandCode;
char Parm1[80], Parm2[80], Parm3[80];

switch (message) {
case WM_COMMAND:
if (wParam >= IDD_GCMDI && wParam <= IDD_GCMDV) {
CommandCode = CommandTable[wParam - IDD_GCMDI];
CheckRadioButton(hDlg, IDD_GCMDI, IDD_GCMDV, wParam);
return(TRUE);
}

switch (wParam) {
case IDD_OK:
GetDlgItemText(hDlg, IDD_PARM1, Parm1, 80);
GetDlgItemText(hDlg, IDD_PARM2, Parm2, 80);
GetDlgItemText(hDlg, IDD_PARM3, Parm3, 80);
sprintf(cmarg,"%c%c%s%c%s%c%s", CommandCode,
strlen(Parm1), Parm1,
strlen(Parm2), Parm2,
strlen(Parm3), Parm3);
EndDialog(hDlg, TRUE);
break;

case IDD_CANCEL:
EndDialog(hDlg, FALSE);
break;

default:
return(FALSE);
break;
}
break;

case WM_INITDIALOG:
CheckRadioButton(hDlg, IDD_GCMDI, IDD_GCMDV, IDD_GCMDI);
SendDlgItemMessage(hDlg, IDD_PARM1, EM_LIMITTEXT, 79, 0L);
SendDlgItemMessage(hDlg, IDD_PARM2, EM_LIMITTEXT, 79, 0L);
SendDlgItemMessage(hDlg, IDD_PARM3, EM_LIMITTEXT, 79, 0L);
break;

default:
return(FALSE);
}
return(TRUE);
}

//-----------------------------------------------------------------------------
BOOL StartKermit(int Command)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
lpXfrDlgProc = MakeProcInstance(StatusDlgProc, hAppInst);
hXfrWnd = CreateDialog(hAppInst, "StatusDlgBox", hAppWnd,
lpXfrDlgProc);
ShowWindow(hXfrWnd, SW_SHOWNA);

SetKermitCommands("StopMenu", MF_ENABLED);
EnableConfigCommands(MF_GRAYED);

tmsg("\n\rStarting Kermit (Command: %c)", Command);

cx = cz = cr = ce = cc = FALSE;
start = Command;
bKermit = TRUE;

return(TRUE);
}

//-----------------------------------------------------------------------------
BOOL EndKermit(int Result)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
SetKermitCommands("StartMenu", MF_ENABLED);
EnableConfigCommands(MF_ENABLED);

if (hSendList) {
DestroyWindow(hSendList);
hSendList = NULL;
}

DestroyWindow(hXfrWnd);
FreeProcInstance(lpXfrDlgProc);
bKermit = FALSE;

tmsg("\n\rKermit Finished (Result: %i), Ribbit...\n\r", Result);

return(TRUE);
}

//-----------------------------------------------------------------------------
BOOL AbortXfer(BOOL bVerify)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
if (bVerify) {
MessageBeep(0);
if (MessageBox(hAppWnd, "Abort Kermit Protocol in Progress",
szAppName, MB_OKCANCEL | MB_ICONQUESTION) != IDD_OK)
return(FALSE);
}

EndKermit(-1);
return(TRUE);
}

//-----------------------------------------------------------------------------
VOID KermitUserInt(WORD IntCmd)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
switch (IntCmd) {
case IDM_CANFILE:
cx = TRUE;
break;

case IDM_CANBATCH:
cz = TRUE;
break;

case IDM_RETRY:
cr = TRUE;
break;

case IDM_STOP:
ce = TRUE;
break;

case IDM_ABORT:
cc = TRUE;
break;
}
}

//-----------------------------------------------------------------------------
BOOL KermitSend()

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
BOOL Result;

if (!GoDialogBox(hAppInst, "SendDlgBox", hAppWnd, SendDlgProc))
return(FALSE);

nfils = 0;
Result = StartKermit(KERMITSEND);

return(Result);
}

//-----------------------------------------------------------------------------
BOOL KermitReceive()

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
return(StartKermit(KERMITRECEIVE));
}

//-----------------------------------------------------------------------------
BOOL KermitServer()

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
return(StartKermit(KERMITSERVER));
}

//-----------------------------------------------------------------------------
BOOL KermitGet()

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
if (GoDialogBox(hAppInst, "GetDlgBox", hAppWnd, GetDlgProc))
return(StartKermit(KERMITGET));
else
return(FALSE);
}

//-----------------------------------------------------------------------------
BOOL KermitHost()

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
if (GoDialogBox(hAppInst, "HostDlgBox", hAppWnd, HostDlgProc))
return(StartKermit(KERMITHOST));
else
return(FALSE);
}

//-----------------------------------------------------------------------------
BOOL KermitGeneric()

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
BOOL Result;

if (GoDialogBox(hAppInst, "GenericDlgBox", hAppWnd, GenericDlgProc))
return(StartKermit(KERMITGENERIC));
else
return(FALSE);
}


  3 Responses to “Category : C Source Code
Archive   : WINKERM.ZIP
Filename : KERMWND.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/