|
|
1.1 ! root 1: /*==============================================================*\ ! 2: * img_init.c - routines for initialization ! 3: * Created 1989, 1990 IBM, Microsoft 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() ! 14: * InitMainWindow(hwnd, mp1, mp2) ! 15: * InitGlobalVars() ! 16: * InitClientArea(hwnd) ! 17: * ! 18: * ! 19: \*==============================================================*/ ! 20: /*--------------------------------------------------------------*\ ! 21: * Include files, macros, defined constants, and externs * ! 22: \*--------------------------------------------------------------*/ ! 23: #define INCL_DOSPROCESS ! 24: #define INCL_DOSERRORS ! 25: #define INCL_WINWINDOWMGR ! 26: #define INCL_WINFRAMEMGR ! 27: #define INCL_WINSYS ! 28: #define INCL_WINPOINTERS ! 29: #define INCL_GPIPRIMITIVES ! 30: ! 31: #include <os2.h> ! 32: #include "img_main.h" ! 33: #include "img_xtrn.h" ! 34: ! 35: /*--------------------------------------------------------------*\ ! 36: * Entry point declarations * ! 37: \*--------------------------------------------------------------*/ ! 38: BOOL InitMainWindow(VOID); ! 39: BOOL InitGlobalVars(VOID); ! 40: BOOL InitClientArea(HWND hwnd); ! 41: ! 42: /*--------------------------------------------------------------*\ ! 43: * static variables * ! 44: \*--------------------------------------------------------------*/ ! 45: CHAR szAppName[CCHAPPNAME]; /* application title */ ! 46: #define RETURN_ERROR 1 /* error return in DosExit */ ! 47: ! 48: /****************************************************************\ ! 49: * Initialization routine * ! 50: *--------------------------------------------------------------* ! 51: * * ! 52: * Name: Init() * ! 53: * * ! 54: * Purpose: Performs initialization functions. * ! 55: * * ! 56: * Usage: Called once before the main window is created. * ! 57: * * ! 58: * Method: * ! 59: * - register all window classes * ! 60: * - setup main application window * ! 61: * - set global variables * ! 62: * * ! 63: * Returns: * ! 64: * NO_ERROR - initiaization is successful * ! 65: * String_ID - initialization failed * ! 66: \****************************************************************/ ! 67: USHORT Init(VOID) ! 68: { ! 69: /* Add ExitProc to the exit list to handle the exit processing. If ! 70: * there is an error, then terminate the process since there have ! 71: * not been any resources allocated yet ! 72: */ ! 73: if (DosExitList(EXLST_ADD, (PFNEXITLIST)ExitProc)) { ! 74: MessageBox(HWND_DESKTOP, ! 75: IDMSG_CANNOTLOADEXITLIST, 0, ! 76: MB_OK | MB_ERROR, ! 77: TRUE); ! 78: DosExit(EXIT_PROCESS, RETURN_ERROR); ! 79: } ! 80: ! 81: /* load application name from resource file */ ! 82: if (!WinLoadString(vhab, NULL, IDS_APPNAME, CCHAPPNAME, szAppName)) ! 83: return IDMSG_CANNOTLOADSTRING; ! 84: ! 85: /* register the main client window class */ ! 86: if (!WinRegisterClass(vhab, ! 87: szAppName, ! 88: (PFNWP)MainWndProc, ! 89: 0L, ! 90: 0)) ! 91: return IDMSG_INITFAILED; ! 92: ! 93: /* ! 94: * create main application window & detach scrollbars ! 95: */ ! 96: if (!InitMainWindow()) ! 97: return IDMSG_MAINWINCREATEFAILED; ! 98: ! 99: /* ! 100: * set up globals used for sizing & system pointers ! 101: */ ! 102: if (!InitGlobalVars()) ! 103: return IDMSG_INITFAILED; ! 104: ! 105: /* ! 106: * this function prepares the application for loading images ! 107: */ ! 108: InitClientArea(vhwndClient); ! 109: ! 110: /* ! 111: * initialise help mechanism ! 112: */ ! 113: #ifdef HELP_MANAGER_ENABLED ! 114: HelpInit(); ! 115: #endif ! 116: ! 117: return NO_ERROR; ! 118: ! 119: } /* Init() */ ! 120: ! 121: /****************************************************************\ ! 122: * Main Window Setup Routine * ! 123: *--------------------------------------------------------------* ! 124: * * ! 125: * Name: InitMainWindow() * ! 126: * * ! 127: * Purpose: Creates the application window and puts it into * ! 128: * it's initial state. * ! 129: * * ! 130: * Usage: Called once by the Init() routine * ! 131: * * ! 132: * Method: * ! 133: * - create main application window * ! 134: * - detach scrollbars from window * ! 135: * - subclass frame window procedure * ! 136: * * ! 137: * Returns: * ! 138: * TRUE - window successfully created * ! 139: * FALSE - window creation failed * ! 140: \****************************************************************/ ! 141: BOOL InitMainWindow(VOID) ! 142: { ! 143: ULONG ctlData = FCF_STANDARD | FCF_VERTSCROLL | FCF_HORZSCROLL; ! 144: ! 145: /* ! 146: * create a window with standard controls ! 147: */ ! 148: vhwndFrame = WinCreateStdWindow( ! 149: HWND_DESKTOP, ! 150: WS_VISIBLE, ! 151: &ctlData, ! 152: szAppName, ! 153: (PSZ)NULL, ! 154: WS_CLIPCHILDREN, ! 155: (HMODULE)NULL, ! 156: IDR_MAIN, ! 157: &vhwndClient); ! 158: if (!vhwndFrame) ! 159: return FALSE; ! 160: ! 161: /* ! 162: * for the time being detach the scrollbars from the main ! 163: * window - but remember their handles for later ! 164: */ ! 165: vhwndVScroll = WinWindowFromID(vhwndFrame, FID_VERTSCROLL); ! 166: vhwndHScroll = WinWindowFromID(vhwndFrame, FID_HORZSCROLL); ! 167: WinSetParent(vhwndVScroll, HWND_OBJECT, FALSE); ! 168: WinSetParent(vhwndHScroll, HWND_OBJECT, FALSE); ! 169: WinSendMsg(vhwndFrame, WM_UPDATEFRAME, ! 170: MPFROMLONG(FCF_VERTSCROLL | FCF_HORZSCROLL), 0L); ! 171: ! 172: /* save menubar handle */ ! 173: vhwndMenu = WinWindowFromID(vhwndFrame, FID_MENU); ! 174: ! 175: /* ! 176: * the frame window procedure is subclassed, so that frame-sizing ! 177: * restrictions can be implemented. ! 178: */ ! 179: if (!WinRegisterClass(vhab, ! 180: "SUBFRAME", ! 181: (PFNWP)FrameWndProc, ! 182: 0L, ! 183: 0)) ! 184: return FALSE; ! 185: vpfnwpFrame = WinSubclassWindow(vhwndFrame, (PFNWP)FrameWndProc); ! 186: ! 187: return TRUE; ! 188: ! 189: } /* InitMainWindow() */ ! 190: ! 191: /****************************************************************\ ! 192: * Client Area Preparation * ! 193: *--------------------------------------------------------------* ! 194: * * ! 195: * Name: InitClientArea() * ! 196: * * ! 197: * Purpose: Prepares the client area to accept the images * ! 198: * * ! 199: * Usage: Called once by the Init() routine * ! 200: * * ! 201: * Method: * ! 202: * - obtain a window device context * ! 203: * - define the image presentation space * ! 204: * - associate the two * ! 205: * - set foreground/background colours & * ! 206: * background mix for the presentation space * ! 207: * Returns: * ! 208: * TRUE - client area successfully setup * ! 209: * FALSE - client area setup failed * ! 210: \****************************************************************/ ! 211: BOOL InitClientArea(hwnd) ! 212: HWND hwnd; /* client window handle */ ! 213: { ! 214: SIZEL sizl; ! 215: ! 216: sizl.cx = 0L; /* set size to default for device */ ! 217: sizl.cy = 0L; /* (full screen) */ ! 218: ! 219: vhdc = WinOpenWindowDC(hwnd); ! 220: if (!vhdc) ! 221: return FALSE; ! 222: ! 223: vhps = GpiCreatePS(vhab, ! 224: vhdc, ! 225: &sizl, ! 226: (ULONG)PU_PELS | GPIT_NORMAL | GPIA_ASSOC ! 227: ); ! 228: if (!vhps) ! 229: return FALSE; ! 230: ! 231: GpiSetColor(vhps, vlForeClr); ! 232: GpiSetBackColor(vhps, vlBackClr); ! 233: GpiSetBackMix(vhps, BM_OVERPAINT); ! 234: ! 235: return TRUE; ! 236: ! 237: } /* InitClientArea() */ ! 238: ! 239: /****************************************************************\ ! 240: * Global Variable Initialisation Routine * ! 241: *--------------------------------------------------------------* ! 242: * * ! 243: * Name: InitGlobalVars() * ! 244: * * ! 245: * Purpose: Performs initialization of the application * ! 246: * global variables * * * ! 247: * Usage: Called once by the Init() routine * ! 248: * * ! 249: * Returns: * ! 250: * TRUE - initialization is successful * ! 251: * FALSE - initialization failed * ! 252: * * ! 253: \****************************************************************/ ! 254: BOOL InitGlobalVars(VOID) ! 255: { ! 256: /* load system sizes */ ! 257: vlXScreen = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN); ! 258: vlYScreen = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN); ! 259: vlcxVScroll = WinQuerySysValue(HWND_DESKTOP, SV_CXVSCROLL); ! 260: vlcyHScroll = WinQuerySysValue(HWND_DESKTOP, SV_CYHSCROLL); ! 261: vlcyTitle = WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR); ! 262: vlcyMenu = WinQuerySysValue(HWND_DESKTOP, SV_CYMENU); ! 263: vlcxBorder = WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER); ! 264: vlcyBorder = WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER); ! 265: ! 266: /* load system pointers */ ! 267: vhptrArrow = WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE); ! 268: vhptrWait = WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT, FALSE); ! 269: return TRUE; ! 270: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.