home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
windows
/
winkerm.zip
/
WININT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1986-10-10
|
11KB
|
363 lines
/***************************************************************************
*
* Winint.c
*
* Winint is the initialization segment. It can be discarded after its use.
*
***************************************************************************/
#include <windows.h>
#include "winkrm.h"
/* These local functions are declared NEAR */
BOOL NEAR KermRegClass(HANDLE);
void NEAR GetFirstInstStrings(HANDLE);
void NEAR GetNextInstData(HANDLE, HANDLE);
void NEAR CreateKermWnd(HANDLE);
void NEAR InsertAbout(HANDLE);
BOOL NEAR InitGlobals(void);
void NEAR GetTextSize(void);
void NEAR CreateScreenFont(void);
/***************************************************************************
*
* WinKermInit
*
* Initialize the program.
*
* Entry: Same parameters passed to WinMain from Windows.
*
* Exit: TRUE if successful, FALSE if not.
*
***************************************************************************/
BOOL FAR WinKermInit(hInstance, hPrevInstance,lpszCmdLine,cmdShow)
HANDLE hInstance;
HANDLE hPrevInstance;
LPSTR lpszCmdLine;
int cmdShow;
{
if (!hPrevInstance) {
GetFirstInstStrings(hInstance); /* load the strings or ... */
if (!KermRegClass(hInstance))
return(FALSE);
}
else
GetNextInstData(hInstance, hPrevInstance); /* get them from prev inst */
hInst = hInstance; /* save this for later */
CreateKermWnd(hInstance); /* create the main tiled window */
hKermDC = GetDC(hKermWnd); /* get a private DC */
InsertAbout(hInstance); /* insert About into system menu */
CreateScreenFont(); /* create a logical font and select it */
GetTextSize(); /* measure the text size */
if (!InitGlobals())
return FALSE; /* failed */
ShowWindow(hKermWnd,cmdShow); /* show the window if globals OK */
return(TRUE);
}
/***************************************************************************
*
* KermRegClass
*
* Registe the Kermit window class.
*
* Entry: Instance handle
*
* Exit: TRUE if successful, FALSE if not.
*
* Notes: As currently implemented, the ICON is hot and we own our own DC.
*
***************************************************************************/
BOOL NEAR KermRegClass(hInstance)
HANDLE hInstance;
{
PWNDCLASS pKermWndClass;
pKermWndClass = (PWNDCLASS)LocalAlloc( LPTR, sizeof(WNDCLASS));
pKermWndClass->hCursor = LoadCursor(NULL, IDC_ARROW);
pKermWndClass->hIcon = NULL;
pKermWndClass->lpszMenuName = (LPSTR)szAppName;
pKermWndClass->lpszClassName = (LPSTR)szAppName;
pKermWndClass->hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH);
pKermWndClass->hInstance = hInstance;
pKermWndClass->style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
pKermWndClass->lpfnWndProc = WinKermWndProc;
if (!RegisterClass((LPWNDCLASS)pKermWndClass))
return(FALSE);
LocalFree((HANDLE)pKermWndClass);
return(TRUE);
}
/***************************************************************************
*
* GetFirstInstStrings
*
* If first instance of program, load the strings from resource segment.
*
* Entry: Instance handle,
*
* Exit: None
*
***************************************************************************/
void NEAR GetFirstInstStrings(hInstance)
HANDLE hInstance;
{
LoadString(hInstance, APPNAME, (LPSTR)szAppName, sizeof(szAppName));
LoadString(hInstance, APPABOUT, (LPSTR)szAbout, sizeof(szAbout));
LoadString(hInstance, TITLE, (LPSTR)szWinTitle,sizeof(szWinTitle));
LoadString(hInstance, COM1STR, (LPSTR)szCom1, 5);
LoadString(hInstance, COM2STR, (LPSTR)szCom2, 5);
LoadString(hInstance, STATESTRING, (LPSTR)StateLabel, sizeof(StateLabel));
LoadString(hInstance, FILESTRING, (LPSTR)FileLabel, sizeof(FileLabel));
LoadString(hInstance, PACKETSTRING, (LPSTR)PacketLabel, sizeof(PacketLabel));
}
/***************************************************************************
*
* GetNextInstData
*
* If not first instance of program, load the data from previous instance.
*
* Entry: Instance handle,
*
* Exit: None
*
***************************************************************************/
void NEAR GetNextInstData(hInstance, hPrevInstance)
HANDLE hInstance;
HANDLE hPrevInstance;
{
GetInstanceData(hPrevInstance, (PSTR)szAppName, sizeof(szAppName));
GetInstanceData(hPrevInstance, (PSTR)szAbout, sizeof(szAbout));
GetInstanceData(hPrevInstance, (PSTR)szWinTitle, sizeof(szWinTitle));
GetInstanceData(hPrevInstance, (PSTR)szCom1, 5);
GetInstanceData(hPrevInstance, (PSTR)szCom2, 5);
GetInstanceData(hPrevInstance, (PSTR)StateLabel, sizeof(StateLabel));
GetInstanceData(hPrevInstance, (PSTR)PacketLabel, sizeof(PacketLabel));
GetInstanceData(hPrevInstance, (PSTR)FileLabel, sizeof(FileLabel));
/* this little trick gives a unique window title to each invocation */
szWinTitle[strlen(szWinTitle)-1] += 1;
}
/***************************************************************************
*
* CreateKermWind
*
* Create the tiled, main window for the program.
*
* Entry: Instance handle,
*
* Exit: None
*
***************************************************************************/
void NEAR CreateKermWnd(hInstance)
HANDLE hInstance;
{
hKermWnd = CreateWindow((LPSTR)szAppName,
(LPSTR)szWinTitle,
WS_TILEDWINDOW,
0,0,0,0,
(HWND)NULL,
(HMENU)NULL, /* uses class menu */
(HANDLE)hInstance,
(LPSTR)NULL
);
}
/***************************************************************************
*
* InsertAbout
*
* Insert 'About' into the system menu.
*
* Entry: Instance handle,
*
* Exit: None
*
***************************************************************************/
void NEAR InsertAbout(hInstance)
HANDLE hInstance;
{
HMENU hMenu;
lpprocAbout = MakeProcInstance((FARPROC)About, hInstance);
hMenu = GetSystemMenu(hKermWnd, FALSE);
ChangeMenu(hMenu,0,NULL,999, MF_APPEND | MF_SEPARATOR);
ChangeMenu(hMenu,0,(LPSTR)szAbout, APPABOUT, MF_APPEND | MF_STRING);
}
/***************************************************************************
*
* InitGlobals
*
* Initialize Global variables.
*
* Entry: Instance handle,
*
* Exit: None
*
* Notes: Many of these steps can also be carried out in response
* to the WM_CREATE message.
*
***************************************************************************/
BOOL NEAR InitGlobals()
{
int temp;
cid = MAXCOMMERR; /* cid < 0 means comm port not open */
CurrentPort = 0; /* menu tracking items */
CurrentState = 0;
Xpos = 0; /* x and y logical coordinates on screen */
Ypos = 0;
if ((ScreenBuf = (char *)LocalAlloc(LPTR, MaxChars)) == NULL) {
MessageBox(hKermWnd, (LPSTR)"Cannot create screen buffer",
(LPSTR)szWinTitle, MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
ScreenBufHead = 0; /* initialize memory screen pointers */
PosInLine = 0; /* -- and values */
CurrentLine = 0;
FirstLine = 0;
/* Make proc instance for the send dialog box */
lpprocSendBox = MakeProcInstance((FARPROC)GetSendFile, hInst);
/* now set all the comm port values */
ComDCB.ByteSize = 8;
ComDCB.Parity = NOPARITY;
ComDCB.StopBits = ONESTOPBIT;
ComDCB.RlsTimeout = 0;
ComDCB.CtsTimeout = 0;
ComDCB.DsrTimeout = 0;
ComDCB.fBinary = TRUE;
ComDCB.fRtsDisable = FALSE;
ComDCB.fParity = FALSE;
ComDCB.fOutxCtsFlow = FALSE;
ComDCB.fOutxDsrFlow = FALSE;
ComDCB.fDtrDisable = FALSE;
ComDCB.fOutX = FALSE;
ComDCB.fInX = TRUE;
ComDCB.PeChar = NULL;
ComDCB.fNull = TRUE;
ComDCB.fChEvt = FALSE;
ComDCB.fDtrflow = FALSE;
ComDCB.fRtsflow = FALSE;
ComDCB.XonChar = 17;
ComDCB.XoffChar = 19;
ComDCB.XonLim = RXBUFSIZE /8;
ComDCB.XoffLim = RXBUFSIZE /8;
ComDCB.PeChar = NULL;
ComDCB.EvtChar = NULL;
ComDCB.EofChar = 26;
ComDCB.TxDelay = 0;
/* Read the initialization stuff from win.ini */
temp = GetProfileInt( (LPSTR)"WinKrm", (LPSTR)"Baud", 1200);
switch (temp) {
case 300:
ComDCB.BaudRate = 300;
CurrentBaud = BAUD300;
break;
case 2400:
ComDCB.BaudRate = 2400;
CurrentBaud = BAUD2400;
break;
case 1200:
default:
ComDCB.BaudRate = 1200;
CurrentBaud = BAUD1200;
break;
}
CheckMenuItem(GetMenu(hKermWnd), CurrentBaud, MF_CHECKED);
return TRUE;
}
/***************************************************************************
*
* CreateScreenFont
*
* Change the font to the OEM terminal font. Gives visible control
* characters and a few extra lines.
*
* Entry: None
*
* Exit: Logical font created and font selected to DC.
*
*
***************************************************************************/
void NEAR CreateScreenFont()
{
/*
Fill in the data structure for the logical font. Most entries
are zero so that the font mapper gets the default values for
the OEM terminal font. By inserting different values, we could
get a different sized font suitable for, say 132 chars per line, etc.
*/
ScreenFont.lfHeight = 0;
ScreenFont.lfWidth = 0;
ScreenFont.lfEscapement = 0;
ScreenFont.lfOrientation = 0;
ScreenFont.lfWeight = 400;
ScreenFont.lfItalic = 0;
ScreenFont.lfUnderline = 0;
ScreenFont.lfStrikeOut = 0;
ScreenFont.lfCharSet = OEM_CHARSET; /* OEM character set */
ScreenFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
ScreenFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
ScreenFont.lfQuality = DEFAULT_QUALITY;
ScreenFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
strcpy(ScreenFont.lfFaceName, "Terminal");
hScreenFont = CreateFontIndirect((LPLOGFONT)&ScreenFont);
hOldScreenFont = SelectObject(hKermDC, hScreenFont);
}
/***************************************************************************
*
* GetTextSize
*
* Measure the size of the font in terms of logical screen coordinates
* Necessary to determine number of lines to write to a screen and
* number of characters per line.
*
* Entry: None
*
* Exit: Character width and height determined for the current font.
* In addition, the maximum number of characters that could show
* on the screen are calculated. These values are then used
* to determine the memory screen size.
*
***************************************************************************/
void NEAR GetTextSize()
{
TEXTMETRIC TM;
/* This gets the metrics for the font */
GetTextMetrics(hKermDC, (LPTEXTMETRIC)&TM);
CharWidth = TM.tmAveCharWidth;
CharHeight = TM.tmHeight + TM.tmExternalLeading;
/* Now, see how many lines we could have on the whole screen */
MaxDevCoorLen = GetDeviceCaps(hKermDC, HORZRES);
/* Determine the line size in characters */
MaxCharLineLen = MaxDevCoorLen / CharWidth;
/* Determine the maximum number of lines on the screen */
MaxLines = GetDeviceCaps(hKermDC, VERTRES) / CharHeight;
/* Initialize related variables */
LineIncrement = MaxCharLineLen + 2;
MaxChars = LineIncrement * MaxLines;
}