|
|
Microsoft OS/2 SDK 2.0 05-30-1990
/*==============================================================*\
* Init.c - routines for initialization and exit processing
* Created 1990, Microsoft, IBM Corp.
*--------------------------------------------------------------
*
* This module contains the code for application initialization
* as well as the code for exit list processing
*
*--------------------------------------------------------------
*
* This source file contains the following functions:
*
* Init() - initialization routines
* InitMainWindow(hwnd, mp1, mp2)
* ExitProc(usTermCode) - exit list processing procedure
*
\*==============================================================*/
/*--------------------------------------------------------------*\
* Include files, macros, defined constants, and externs
\*--------------------------------------------------------------*/
#define INCL_WINWINDOWMGR
#define INCL_WINMLE
#define INCL_DOSPROCESS
#include <os2.h>
#include <string.h>
#include "sty_main.h"
#include "sty_xtrn.h"
#include "sty_dlg.h"
#define RETURN_ERROR 1 /* error return in DosExit */
/*--------------------------------------------------------------*\
* Global variables
\*--------------------------------------------------------------*/
HWND hwndMLE;
/*--------------------------------------------------------------*\
* Entry point declarations
\*--------------------------------------------------------------*/
/****************************************************************\
* Initialization routine
*--------------------------------------------------------------
*
* Name: Init()
*
* Purpose: Performs initialization functions required
* before the main window can be created.
*
* Usage: Called once before the main window is created.
*
* Method:
* - installs the routine ExitProc into the
* DosExitList chain
* - registers all window classes
* - performs any command line processing
*
* Returns:
* TRUE - initialization is successful
* FALSE - initialization failed
\****************************************************************/
BOOL Init(VOID)
{
/* Add ExitProc to the exit list to handle the exit processing. If
* there is an error, then terminate the process since there have
* not been any resources allocated yet
*/
if(DosExitList(EXLST_ADD, (PFNEXITLIST)ExitProc)) {
MessageBox(HWND_DESKTOP,
IDMSG_CANNOTLOADEXITLIST,
MB_OK | MB_ERROR,
TRUE);
DosExit(EXIT_PROCESS, RETURN_ERROR);
}
/* initialize the print dialog structures */
InitPrintingDialogs();
/* load application name from resource file */
if(!WinLoadString(hab, NULL, IDS_APPNAME, MAXNAMEL, szAppName))
return FALSE;
/* load "untitled" string */
if(!WinLoadString(hab, NULL, IDS_UNTITLED, MESSAGELEN, szUntitled))
return FALSE;
/* register the main client window class */
if(!WinRegisterClass(hab,
(PSZ)szAppName,
(PFNWP)MainWndProc,
CS_SIZEREDRAW | CS_CLIPCHILDREN,
0)) {
return FALSE;
}
/*--------------------------------------------------*\
* Add any command line processing here
\*--------------------------------------------------*/
return TRUE;
} /* Init() */
/****************************************************************\
* Initialization routine
*--------------------------------------------------------------
*
* Name: InitMainWindow(hwnd, mp1, mp2)
*
* Purpose: Performs initialization functions required
* when the main window is created.
*
* Usage: Called once during the WM_CREATE processing when
* the main window is created.
*
* Method:
*
* Returns: value to be returned from the WM_CREATE message:
* TRUE - window creation should stop
* FALSE - window creation should continue
\****************************************************************/
MRESULT InitMainWindow(hwnd, mp1, mp2)
HWND hwnd; /* handle to the main client window */
MPARAM mp1; /* first parameter of WM_CREATE message */
MPARAM mp2; /* second parameter of WM_CREATE message */
{
RECTL rcl;
UpdateTitleText(((PCREATESTRUCT)PVOIDFROMMP(mp2))->hwndParent);
WinQueryWindowRect(hwnd, (PRECTL)&rcl);
/* create MLE window the same size as the client */
hwndMLE = WinCreateWindow(hwnd,
WC_MLE,
(PSZ)NULL,
MLS_HSCROLL | MLS_VSCROLL | WS_VISIBLE,
(SHORT)rcl.xLeft,
(SHORT)rcl.yBottom,
(SHORT)rcl.xRight,
(SHORT)rcl.yTop,
hwnd,
HWND_TOP,
ID_MLE,
NULL,
NULL);
if(!hwndMLE)
return (MRESULT)TRUE;
/* return FALSE to continue window creation, TRUE to abort it */
return (MRESULT)FALSE;
/* This routine currently doesn't use the mp1 and mp2 parameters so *\
* it is referenced here to prevent an 'Unreferenced Parameter'
\* warning at compile time */
mp1;
mp2;
} /* InitMainWindow() */
/****************************************************************\
* Exit list processing procedure
*--------------------------------------------------------------
*
* Name: ExitProc(usTermCode)
*
* Purpose: Cleans up certain resources when the application
* terminates
*
* Usage: Routine is called by DosExitList when the
* application exits
*
* Method: global resources, such as the main window and
* message queue, are destroyed and any system
* resources used are freed
*
* Returns: Returns EXLST_EXIT to the DosExitList handler
*
\****************************************************************/
VOID PASCAL FAR ExitProc(usTermCode)
USHORT usTermCode; /* code for the reason for termination */
{
/* destroy the main window if it exists */
if(WinIsWindow(hab, hwndMainFrame))
WinDestroyWindow(hwndMainFrame);
/*--------------------------------------------------*\
* Any other system resources used
* (e.g. memory or files) should be freed here
\*--------------------------------------------------*/
WinDestroyMsgQueue(hmq);
WinTerminate(hab);
DosExitList(EXLST_EXIT, 0L); /* termination complete */
/* This routine currently doesn't use the usTermCode parameter so *\
* it is referenced here to prevent an 'Unreferenced Parameter'
\* warning at compile time */
usTermCode;
} /* ExitProc() */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.