home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 December
/
simtel1292_SIMTEL_1292_Walnut_Creek.iso
/
msdos
/
progjorn
/
pj_6_4.arc
/
SMLTPLNT.C
< prev
next >
Wrap
Text File
|
1988-04-28
|
3KB
|
118 lines
/*
Initialization segment for the Windows small memory model template.
This code can be discarded after it is used.
*/
#include <windows.h>
#include "smltpl.h"
/* local function declarations */
static BOOL NEAR RegisterWindowClass(HANDLE);
static void NEAR GetPrevInstanceData(HANDLE);
static BOOL NEAR MakeAndShowMainWnd(HANDLE, HANDLE, int);
/* This routine is FAR since it is called from another segment */
BOOL FAR InitProgram(hInstance,hPrevInstance, lpszCmdLine, cmdShow)
HANDLE hInstance, hPrevInstance;
LPSTR lpszCmdLine;
int cmdShow;
{
/* if this is the first instance of the program ... */
if (!hPrevInstance) {
/* register the window */
if (!RegisterWindowClass(hInstance))
return FALSE;
}
/* A previous instance already exists so get global data from there */
else
GetPrevInstanceData(hPrevInstance);
/* Create and show the window */
if (!MakeAndShowMainWnd(hInstance,hPrevInstance, cmdShow))
return FALSE;
return TRUE;
}
/* Every window must belong to a class. We register ours here */
static BOOL NEAR RegisterWindowClass(hInstance)
HANDLE hInstance;
{
PWNDCLASS pWndClass;
HANDLE hTemp;
/* Load the name string from resources */
LoadString(hInstance, IDS_APPNAME,(LPSTR)szAppName,sizeof(szAppName));
/* allocate space for the WNDCLASS structure and lock it down */
hTemp = LocalAlloc(LPTR,sizeof(WNDCLASS));
pWndClass = (PWNDCLASS)LocalLock(hTemp);
/* fill the structure */
pWndClass->hCursor = LoadCursor(NULL, IDC_ARROW); /* standard cursor */
pWndClass->hIcon = NULL; /* no icon */
pWndClass->lpszMenuName = NULL; /* no class menu */
pWndClass->lpszClassName = (LPSTR)szAppName; /* our class name */
pWndClass->hbrBackground = GetStockObject(WHITE_BRUSH); /*white background*/
pWndClass->hInstance = hInstance; /* instance handle */
pWndClass->style = CS_VREDRAW | CS_HREDRAW; /* standard redraw values */
pWndClass->lpfnWndProc = MainWndProc; /* pointer to our window proc */
/* register the class. if fail, abort */
if (!RegisterClass((LPWNDCLASS)pWndClass))
return FALSE;
/* free the memory used */
LocalUnlock(hTemp);
LocalFree(hTemp);
/* show success */
return TRUE;
}
/*
If this not the first instance, we can retrieve static data from a
previous invocation of the program
*/
static void NEAR GetPrevInstanceData(hInstance)
HANDLE hInstance;
{
GetInstanceData(hInstance, (PSTR)szAppName, sizeof(szAppName));
}
/*
Create the window, making sure that its position and size are suitable
for the display.
*/
static BOOL NEAR MakeAndShowMainWnd(hInstance, hPrevInstance, cmdShow)
HANDLE hInstance;
HANDLE hPrevInstance;
int cmdShow;
{
/* create the window, letting it fall where Windows wants */
hWndMain = CreateWindow((LPSTR)szAppName,
(LPSTR)szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,0,
CW_USEDEFAULT,0,
(HWND)NULL,
(HMENU)NULL,
(HANDLE)hInstance,
(LPSTR)NULL);
/* if we fail, give up */
if (hWndMain == NULL)
return FALSE;
/* finally, display the window and show success */
ShowWindow(hWndMain, cmdShow);
UpdateWindow(hWndMain);
return TRUE;
}