|
|
1.1 ! root 1: /*==============================================================*\ ! 2: * Init.c - routines for initialization and exit processing ! 3: * Created 1990, Microsoft, IBM Corp. ! 4: *-------------------------------------------------------------- ! 5: * ! 6: * This module contains the code for application initialization ! 7: * as well as the code for exit list processing ! 8: * ! 9: *-------------------------------------------------------------- ! 10: * ! 11: * This source file contains the following functions: ! 12: * ! 13: * Init() - initialization routines ! 14: * InitMainWindow(hwnd, mp1, mp2) ! 15: * ExitProc(usTermCode) - exit list processing procedure ! 16: * ! 17: \*==============================================================*/ ! 18: ! 19: /*--------------------------------------------------------------*\ ! 20: * Include files, macros, defined constants, and externs ! 21: \*--------------------------------------------------------------*/ ! 22: ! 23: #define INCL_WINWINDOWMGR ! 24: #define INCL_WINMLE ! 25: #define INCL_DOSPROCESS ! 26: ! 27: #include <os2.h> ! 28: #include <string.h> ! 29: #include "sty_main.h" ! 30: #include "sty_xtrn.h" ! 31: #include "sty_dlg.h" ! 32: ! 33: #define RETURN_ERROR 1 /* error return in DosExit */ ! 34: ! 35: /*--------------------------------------------------------------*\ ! 36: * Global variables ! 37: \*--------------------------------------------------------------*/ ! 38: HWND hwndMLE; ! 39: ! 40: /*--------------------------------------------------------------*\ ! 41: * Entry point declarations ! 42: \*--------------------------------------------------------------*/ ! 43: ! 44: /****************************************************************\ ! 45: * Initialization routine ! 46: *-------------------------------------------------------------- ! 47: * ! 48: * Name: Init() ! 49: * ! 50: * Purpose: Performs initialization functions required ! 51: * before the main window can be created. ! 52: * ! 53: * Usage: Called once before the main window is created. ! 54: * ! 55: * Method: ! 56: * - installs the routine ExitProc into the ! 57: * DosExitList chain ! 58: * - registers all window classes ! 59: * - performs any command line processing ! 60: * ! 61: * Returns: ! 62: * TRUE - initialization is successful ! 63: * FALSE - initialization failed ! 64: \****************************************************************/ ! 65: BOOL Init(VOID) ! 66: { ! 67: ! 68: /* Add ExitProc to the exit list to handle the exit processing. If ! 69: * there is an error, then terminate the process since there have ! 70: * not been any resources allocated yet ! 71: */ ! 72: if(DosExitList(EXLST_ADD, (PFNEXITLIST)ExitProc)) { ! 73: MessageBox(HWND_DESKTOP, ! 74: IDMSG_CANNOTLOADEXITLIST, ! 75: MB_OK | MB_ERROR, ! 76: TRUE); ! 77: DosExit(EXIT_PROCESS, RETURN_ERROR); ! 78: } ! 79: ! 80: /* initialize the print dialog structures */ ! 81: InitPrintingDialogs(); ! 82: ! 83: /* load application name from resource file */ ! 84: if(!WinLoadString(hab, NULL, IDS_APPNAME, MAXNAMEL, szAppName)) ! 85: return FALSE; ! 86: ! 87: /* load "untitled" string */ ! 88: if(!WinLoadString(hab, NULL, IDS_UNTITLED, MESSAGELEN, szUntitled)) ! 89: return FALSE; ! 90: ! 91: /* register the main client window class */ ! 92: if(!WinRegisterClass(hab, ! 93: (PSZ)szAppName, ! 94: (PFNWP)MainWndProc, ! 95: CS_SIZEREDRAW | CS_CLIPCHILDREN, ! 96: 0)) { ! 97: return FALSE; ! 98: } ! 99: ! 100: /*--------------------------------------------------*\ ! 101: * Add any command line processing here ! 102: \*--------------------------------------------------*/ ! 103: ! 104: ! 105: return TRUE; ! 106: ! 107: } /* Init() */ ! 108: ! 109: /****************************************************************\ ! 110: * Initialization routine ! 111: *-------------------------------------------------------------- ! 112: * ! 113: * Name: InitMainWindow(hwnd, mp1, mp2) ! 114: * ! 115: * Purpose: Performs initialization functions required ! 116: * when the main window is created. ! 117: * ! 118: * Usage: Called once during the WM_CREATE processing when ! 119: * the main window is created. ! 120: * ! 121: * Method: ! 122: * ! 123: * Returns: value to be returned from the WM_CREATE message: ! 124: * TRUE - window creation should stop ! 125: * FALSE - window creation should continue ! 126: \****************************************************************/ ! 127: MRESULT InitMainWindow(hwnd, mp1, mp2) ! 128: HWND hwnd; /* handle to the main client window */ ! 129: MPARAM mp1; /* first parameter of WM_CREATE message */ ! 130: MPARAM mp2; /* second parameter of WM_CREATE message */ ! 131: { ! 132: RECTL rcl; ! 133: ! 134: ! 135: UpdateTitleText(((PCREATESTRUCT)PVOIDFROMMP(mp2))->hwndParent); ! 136: ! 137: WinQueryWindowRect(hwnd, (PRECTL)&rcl); ! 138: ! 139: /* create MLE window the same size as the client */ ! 140: hwndMLE = WinCreateWindow(hwnd, ! 141: WC_MLE, ! 142: (PSZ)NULL, ! 143: MLS_HSCROLL | MLS_VSCROLL | WS_VISIBLE, ! 144: (SHORT)rcl.xLeft, ! 145: (SHORT)rcl.yBottom, ! 146: (SHORT)rcl.xRight, ! 147: (SHORT)rcl.yTop, ! 148: hwnd, ! 149: HWND_TOP, ! 150: ID_MLE, ! 151: NULL, ! 152: NULL); ! 153: ! 154: if(!hwndMLE) ! 155: return (MRESULT)TRUE; ! 156: ! 157: /* return FALSE to continue window creation, TRUE to abort it */ ! 158: return (MRESULT)FALSE; ! 159: ! 160: /* This routine currently doesn't use the mp1 and mp2 parameters so *\ ! 161: * it is referenced here to prevent an 'Unreferenced Parameter' ! 162: \* warning at compile time */ ! 163: ! 164: mp1; ! 165: mp2; ! 166: ! 167: ! 168: } /* InitMainWindow() */ ! 169: ! 170: ! 171: /****************************************************************\ ! 172: * Exit list processing procedure ! 173: *-------------------------------------------------------------- ! 174: * ! 175: * Name: ExitProc(usTermCode) ! 176: * ! 177: * Purpose: Cleans up certain resources when the application ! 178: * terminates ! 179: * ! 180: * Usage: Routine is called by DosExitList when the ! 181: * application exits ! 182: * ! 183: * Method: global resources, such as the main window and ! 184: * message queue, are destroyed and any system ! 185: * resources used are freed ! 186: * ! 187: * Returns: Returns EXLST_EXIT to the DosExitList handler ! 188: * ! 189: \****************************************************************/ ! 190: VOID PASCAL FAR ExitProc(usTermCode) ! 191: USHORT usTermCode; /* code for the reason for termination */ ! 192: { ! 193: ! 194: /* destroy the main window if it exists */ ! 195: if(WinIsWindow(hab, hwndMainFrame)) ! 196: WinDestroyWindow(hwndMainFrame); ! 197: ! 198: /*--------------------------------------------------*\ ! 199: * Any other system resources used ! 200: * (e.g. memory or files) should be freed here ! 201: \*--------------------------------------------------*/ ! 202: ! 203: WinDestroyMsgQueue(hmq); ! 204: ! 205: WinTerminate(hab); ! 206: ! 207: DosExitList(EXLST_EXIT, 0L); /* termination complete */ ! 208: ! 209: /* This routine currently doesn't use the usTermCode parameter so *\ ! 210: * it is referenced here to prevent an 'Unreferenced Parameter' ! 211: \* warning at compile time */ ! 212: ! 213: usTermCode; ! 214: ! 215: } /* ExitProc() */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.