home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
windows
/
winkerm.zip
/
WINWND.C
< prev
Wrap
C/C++ Source or Header
|
1986-10-10
|
7KB
|
263 lines
/***************************************************************************
*
* Winwnd
*
* Kermit window procedure and support modules.
*
***************************************************************************/
#include <windows.h>
#include "winkrm.h"
void NEAR KermPaint(HDC, RECT);
/***************************************************************************
*
* WinKermWndProc
*
* Kermit window proceedure
*
***************************************************************************/
LONG FAR PASCAL WinKermWndProc(hWnd,message,wParam,lParam)
HWND hWnd;
unsigned message;
WORD wParam;
LONG lParam;
{
PAINTSTRUCT ps;
int result;
/* handle messages for main, tiled window */
if (hWnd == hKermWnd) {
switch (message) {
case WM_COMMAND:
KerCommand(hWnd,wParam,lParam);
break;
case WM_SIZE:
ReleaseDC(hKermWnd, hKermDC);
if (!(( lParam == 0) && (wParam == SIZENORMAL))) {
ScreenLineLen = (LOWORD(lParam)) / CharWidth;
XClientSize = ScreenLineLen * CharWidth;
CurrentMaxLine = (HIWORD(lParam)) / CharHeight;
YClientSize = CurrentMaxLine * CharHeight;
CurrentMaxLine = CurrentMaxLine * (MaxCharLineLen+2);
MaxLinesOnScreen = CurrentMaxLine / LineIncrement;
}
hKermDC = GetDC(hKermWnd);
break;
case WM_SYSCOMMAND:
if (wParam == APPABOUT)
DialogBox(hInst,MAKEINTRESOURCE(ABOUTBOX),hWnd,lpprocAbout);
else
return(DefWindowProc(hWnd,message,wParam,lParam));
break;
case WM_CLOSE:
result = MessageBox(hKermWnd,
(LPSTR)"Terminate Kermit",
(LPSTR)szWinTitle,
MB_OKCANCEL | MB_ICONQUESTION);
if (result == IDOK) {
if (cid >= 0)
CloseComm(cid);
/*
* free public and private resources, free scratch files, reset baud
* rates, free memory, screen space, and brushes
*/
DestroyWindow(hKermWnd);
}
break;
case WM_QUERYENDSESSION:
result = MessageBox(hKermWnd,
(LPSTR)"Terminate Kermit",
(LPSTR)szWinTitle,
MB_OKCANCEL | MB_ICONQUESTION);
if (result == IDOK)
return (TRUE);
return (FALSE);
break;
case WM_ENDSESSION:
if (wParam == TRUE) {
if (cid >= 0)
CloseComm(cid);
/*
* free public and private resources, free scratch files, reset baud
* rates, free memory, screen space, and brushes
*/
return(TRUE);
}
break;
case WM_CHAR:
if (cid >= 0)
if (CurrentState == CONNECTSTATE) {
static ShortStr[2] = {0,0};
ShortStr[0] = wParam;
WriteComm(cid, (LPSTR)ShortStr,1);
}
break;
case WM_SETFOCUS:
CreateCaret(hWnd, (HBITMAP)NULL, 0, (int)CharHeight);
SetCaretPos(Xpos, Ypos);
ShowCaret(hWnd);
break;
case WM_KILLFOCUS:
HideCaret(hWnd);
DestroyCaret();
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
BeginPaint(hWnd,(LPPAINTSTRUCT)&ps);
HideCaret(hWnd);
KermPaint(ps.hdc, ps.rcPaint);
ShowCaret(hWnd);
EndPaint(hWnd, (LPPAINTSTRUCT)&ps);
break;
default:
return(DefWindowProc(hWnd,message,wParam,lParam));
break;
}
}
/* messages for the Kermit file transfer popup windows */
else if (hWnd == hRXWnd) {
switch(message) {
case WM_PAINT:
BeginPaint(hWnd,(LPPAINTSTRUCT)&ps);
printf("%s %s %s\n", StateLabel, PacketLabel, FileLabel);
TextOut(ps.hdc,0,2,(LPSTR)StateLabel,strlen(StateLabel));
TextOut(ps.hdc,0,CharHeight+2,
(LPSTR)PacketLabel,strlen(PacketLabel));
TextOut(ps.hdc,0,2*CharHeight+2,
(LPSTR)FileLabel,strlen(FileLabel));
TextOut(ps.hdc,9*CharWidth,2,(LPSTR)StateStr,1);
TextOut(ps.hdc,10*CharWidth,CharHeight+2,
(LPSTR)PacketStr,strlen(PacketStr));
TextOut(ps.hdc,8*CharWidth,2*CharHeight+2,
(LPSTR)filnam1,strlen(filnam1));
EndPaint(hWnd, (LPPAINTSTRUCT)&ps);
break;
case WM_SHOWWINDOW:
/* if not intercepted, the file transfer window will hide with the main
* window. This should be made into an option.
*/
break;
default:
return(DefWindowProc(hWnd,message,wParam,lParam));
break;
}
}
else
return(DefWindowProc(hWnd,message,wParam,lParam));
return(0L);
}/* WinKermWndProc */
/***************************************************************************
*
* KermPaint
*
* Paint the main kermit window from the contents of the memor screen bnffer.
*
* Entry: Handle to the main kermit window display context
* and invalid rectangle.
*
* Exit: Kermit main window updated.
*
***************************************************************************/
void NEAR KermPaint(hDC, Rect)
HDC hDC;
RECT Rect;
{
int i, displ, len;
int FirstToCurrent;
int LinesToPrint;
int StartPoint;
int HighLinesToPrint;
int LeftCol, RightCol;
int TopLine, BottomLine;
int LeftRect;
int temp;
LeftCol = Rect.left / CharWidth;
RightCol = (Rect.right + CharWidth - 1) / CharWidth;
LeftRect = LeftCol * CharWidth;
TopLine = Rect.top / CharHeight;
BottomLine = (Rect.bottom + CharHeight - 1) / CharHeight;
FirstToCurrent = CurrentLine - FirstLine;
if (FirstToCurrent < 0)
FirstToCurrent += MaxChars;
LinesToPrint = min(MaxLinesOnScreen, 1 + FirstToCurrent/LineIncrement);
StartPoint = CurrentLine - (LinesToPrint - 1) * LineIncrement;
if (StartPoint >= 0) {
for (i=0; i < LinesToPrint; i++) {
displ = StartPoint + LineIncrement * i;
len = strlen(ScreenBuf + displ);
if ((i < TopLine) || (i > BottomLine))
continue;
if (len <= LeftCol)
continue;
temp = min(len, RightCol) - LeftCol;
TextOut(hDC,LeftRect,i*CharHeight,
(LPSTR)(ScreenBuf+ displ + LeftCol), temp);
}
}
else {
HighLinesToPrint = (-StartPoint / LineIncrement);
StartPoint += MaxChars;
for (i = 0; i < HighLinesToPrint; i++) {
displ = StartPoint + LineIncrement * i;
len = strlen(ScreenBuf + displ);
if ((i < TopLine) || (i > BottomLine))
continue;
if (len <= LeftCol)
continue;
temp = min(len, RightCol) - LeftCol;
TextOut(hDC,LeftRect,i*CharHeight,
(LPSTR)(ScreenBuf+ displ + LeftCol), temp);
}
for (i = HighLinesToPrint; i < LinesToPrint; i++) {
displ = LineIncrement * (i - HighLinesToPrint);
len = strlen(ScreenBuf + displ);
if ((i < TopLine) || (i > BottomLine))
continue;
if (len <= LeftCol)
continue;
temp = min(len, RightCol) - LeftCol;
TextOut(hDC,LeftRect,i*CharHeight,
(LPSTR)(ScreenBuf+ displ + LeftCol), temp);
}
}
Xpos = CharWidth * len;
Ypos = CharHeight * (i - 1);
SetCaretPos(Xpos, Ypos);
}