|
|
Microsoft OS/2 SDK 2.0 05-30-1990
/*==============================================================*\
* img_init.c - routines for initialization
* Created 1989, 1990 IBM, Microsoft 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()
* InitMainWindow(hwnd, mp1, mp2)
* InitGlobalVars()
* InitClientArea(hwnd)
*
*
\*==============================================================*/
/*--------------------------------------------------------------*\
* Include files, macros, defined constants, and externs *
\*--------------------------------------------------------------*/
#define INCL_DOSPROCESS
#define INCL_DOSERRORS
#define INCL_WINWINDOWMGR
#define INCL_WINFRAMEMGR
#define INCL_WINSYS
#define INCL_WINPOINTERS
#define INCL_GPIPRIMITIVES
#include <os2.h>
#include "img_main.h"
#include "img_xtrn.h"
/*--------------------------------------------------------------*\
* Entry point declarations *
\*--------------------------------------------------------------*/
BOOL InitMainWindow(VOID);
BOOL InitGlobalVars(VOID);
BOOL InitClientArea(HWND hwnd);
/*--------------------------------------------------------------*\
* static variables *
\*--------------------------------------------------------------*/
CHAR szAppName[CCHAPPNAME]; /* application title */
#define RETURN_ERROR 1 /* error return in DosExit */
/****************************************************************\
* Initialization routine *
*--------------------------------------------------------------*
* *
* Name: Init() *
* *
* Purpose: Performs initialization functions. *
* *
* Usage: Called once before the main window is created. *
* *
* Method: *
* - register all window classes *
* - setup main application window *
* - set global variables *
* *
* Returns: *
* NO_ERROR - initiaization is successful *
* String_ID - initialization failed *
\****************************************************************/
USHORT 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, 0,
MB_OK | MB_ERROR,
TRUE);
DosExit(EXIT_PROCESS, RETURN_ERROR);
}
/* load application name from resource file */
if (!WinLoadString(vhab, NULL, IDS_APPNAME, CCHAPPNAME, szAppName))
return IDMSG_CANNOTLOADSTRING;
/* register the main client window class */
if (!WinRegisterClass(vhab,
szAppName,
(PFNWP)MainWndProc,
0L,
0))
return IDMSG_INITFAILED;
/*
* create main application window & detach scrollbars
*/
if (!InitMainWindow())
return IDMSG_MAINWINCREATEFAILED;
/*
* set up globals used for sizing & system pointers
*/
if (!InitGlobalVars())
return IDMSG_INITFAILED;
/*
* this function prepares the application for loading images
*/
InitClientArea(vhwndClient);
/*
* initialise help mechanism
*/
#ifdef HELP_MANAGER_ENABLED
HelpInit();
#endif
return NO_ERROR;
} /* Init() */
/****************************************************************\
* Main Window Setup Routine *
*--------------------------------------------------------------*
* *
* Name: InitMainWindow() *
* *
* Purpose: Creates the application window and puts it into *
* it's initial state. *
* *
* Usage: Called once by the Init() routine *
* *
* Method: *
* - create main application window *
* - detach scrollbars from window *
* - subclass frame window procedure *
* *
* Returns: *
* TRUE - window successfully created *
* FALSE - window creation failed *
\****************************************************************/
BOOL InitMainWindow(VOID)
{
ULONG ctlData = FCF_STANDARD | FCF_VERTSCROLL | FCF_HORZSCROLL;
/*
* create a window with standard controls
*/
vhwndFrame = WinCreateStdWindow(
HWND_DESKTOP,
WS_VISIBLE,
&ctlData,
szAppName,
(PSZ)NULL,
WS_CLIPCHILDREN,
(HMODULE)NULL,
IDR_MAIN,
&vhwndClient);
if (!vhwndFrame)
return FALSE;
/*
* for the time being detach the scrollbars from the main
* window - but remember their handles for later
*/
vhwndVScroll = WinWindowFromID(vhwndFrame, FID_VERTSCROLL);
vhwndHScroll = WinWindowFromID(vhwndFrame, FID_HORZSCROLL);
WinSetParent(vhwndVScroll, HWND_OBJECT, FALSE);
WinSetParent(vhwndHScroll, HWND_OBJECT, FALSE);
WinSendMsg(vhwndFrame, WM_UPDATEFRAME,
MPFROMLONG(FCF_VERTSCROLL | FCF_HORZSCROLL), 0L);
/* save menubar handle */
vhwndMenu = WinWindowFromID(vhwndFrame, FID_MENU);
/*
* the frame window procedure is subclassed, so that frame-sizing
* restrictions can be implemented.
*/
if (!WinRegisterClass(vhab,
"SUBFRAME",
(PFNWP)FrameWndProc,
0L,
0))
return FALSE;
vpfnwpFrame = WinSubclassWindow(vhwndFrame, (PFNWP)FrameWndProc);
return TRUE;
} /* InitMainWindow() */
/****************************************************************\
* Client Area Preparation *
*--------------------------------------------------------------*
* *
* Name: InitClientArea() *
* *
* Purpose: Prepares the client area to accept the images *
* *
* Usage: Called once by the Init() routine *
* *
* Method: *
* - obtain a window device context *
* - define the image presentation space *
* - associate the two *
* - set foreground/background colours & *
* background mix for the presentation space *
* Returns: *
* TRUE - client area successfully setup *
* FALSE - client area setup failed *
\****************************************************************/
BOOL InitClientArea(hwnd)
HWND hwnd; /* client window handle */
{
SIZEL sizl;
sizl.cx = 0L; /* set size to default for device */
sizl.cy = 0L; /* (full screen) */
vhdc = WinOpenWindowDC(hwnd);
if (!vhdc)
return FALSE;
vhps = GpiCreatePS(vhab,
vhdc,
&sizl,
(ULONG)PU_PELS | GPIT_NORMAL | GPIA_ASSOC
);
if (!vhps)
return FALSE;
GpiSetColor(vhps, vlForeClr);
GpiSetBackColor(vhps, vlBackClr);
GpiSetBackMix(vhps, BM_OVERPAINT);
return TRUE;
} /* InitClientArea() */
/****************************************************************\
* Global Variable Initialisation Routine *
*--------------------------------------------------------------*
* *
* Name: InitGlobalVars() *
* *
* Purpose: Performs initialization of the application *
* global variables * * *
* Usage: Called once by the Init() routine *
* *
* Returns: *
* TRUE - initialization is successful *
* FALSE - initialization failed *
* *
\****************************************************************/
BOOL InitGlobalVars(VOID)
{
/* load system sizes */
vlXScreen = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
vlYScreen = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
vlcxVScroll = WinQuerySysValue(HWND_DESKTOP, SV_CXVSCROLL);
vlcyHScroll = WinQuerySysValue(HWND_DESKTOP, SV_CYHSCROLL);
vlcyTitle = WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR);
vlcyMenu = WinQuerySysValue(HWND_DESKTOP, SV_CYMENU);
vlcxBorder = WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER);
vlcyBorder = WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER);
/* load system pointers */
vhptrArrow = WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE);
vhptrWait = WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT, FALSE);
return TRUE;
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.