home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / d / d020_1_4 / 5.ddi / MULTIPAD / MPINIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-01  |  4.0 KB  |  134 lines

  1. /***************************************************************************
  2.  *                                       *
  3.  *  MODULE    : MpInit.c                           *
  4.  *                                       *
  5.  *  PURPOSE    : Contains initialization code for MultiPad.           *
  6.  *                                       *
  7.  *  FUNCTIONS    : InitializeApplication() - Sets up Class data structure   *
  8.  *                        and registers window class.    *
  9.  *                                       *
  10.  *          InitializeInstance ()   - Does a per-instance initial-   *
  11.  *                        ization of MultiPad. Creates   *
  12.  *                        the "frame" and MDI client.    *
  13.  *                                       *
  14.  ***************************************************************************/
  15. #include "multipad.h"
  16.  
  17. char szFrame[] = "mpframe";   /* Class name for "frame" window */
  18. char szChild[] = "mpchild";   /* Class name for MDI window     */
  19.  
  20. /****************************************************************************
  21.  *                                        *
  22.  *  FUNCTION   : InitializeApplication ()                    *
  23.  *                                        *
  24.  *  PURPOSE    : Sets up the class data structures and does a one-time        *
  25.  *         initialization of the app by registering the window classes*
  26.  *                                        *
  27.  *  RETURNS    : TRUE  - If RegisterClass() was successful for both classes.*
  28.  *         FALSE - otherwise.                        *
  29.  *                                        *
  30.  ****************************************************************************/
  31.  
  32. BOOL FAR PASCAL InitializeApplication()
  33. {
  34.     WNDCLASS    wc;
  35.  
  36.     /* Register the frame class */
  37.     wc.style         = 0;
  38.     wc.lpfnWndProc   = MPFrameWndProc;
  39.     wc.cbClsExtra    = 0;
  40.     wc.cbWndExtra    = 0;
  41.     wc.hInstance     = hInst;
  42.     wc.hIcon         = LoadIcon(hInst,IDMULTIPAD);
  43.     wc.hCursor         = LoadCursor(NULL,IDC_ARROW);
  44.     wc.hbrBackground = COLOR_APPWORKSPACE+1;
  45.     wc.lpszMenuName  = IDMULTIPAD;
  46.     wc.lpszClassName = szFrame;
  47.  
  48.     if (!RegisterClass (&wc) )
  49.     return FALSE;
  50.  
  51.     /* Register the MDI child class */
  52.     wc.lpfnWndProc   = MPMDIChildWndProc;
  53.     wc.hIcon         = LoadIcon(hInst,IDNOTE);
  54.     wc.lpszMenuName  = NULL;
  55.     wc.cbWndExtra    = CBWNDEXTRA;
  56.     wc.lpszClassName = szChild;
  57.  
  58.     if (!RegisterClass(&wc))
  59.     return FALSE;
  60.  
  61.     return TRUE;
  62.  
  63. }
  64.  
  65. /****************************************************************************
  66.  *                                        *
  67.  *  FUNCTION   : InitializeInstance ()                        *
  68.  *                                        *
  69.  *  PURPOSE    : Performs a per-instance initialization of MultiPad. It     *
  70.  *         also creates the frame and an MDI window.            *
  71.  *                                        *
  72.  *  RETURNS    : TRUE  - If initialization was successful.            *
  73.  *         FALSE - otherwise.                        *
  74.  *                                        *
  75.  ****************************************************************************/
  76. BOOL FAR PASCAL InitializeInstance(LPSTR lpCmdLine, WORD nCmdShow)
  77. {
  78.     extern HWND  hwndMDIClient;
  79.     char     sz[80], *pCmdLine;
  80.     HDC      hdc;
  81.     HMENU     hmenu;
  82.  
  83.     /* Get the base window title */
  84.     LoadString (hInst, IDS_APPNAME, sz, sizeof(sz));
  85.  
  86.     /* Create the frame */
  87.     hwndFrame = CreateWindow (szFrame,
  88.                   sz,
  89.                   WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  90.                   CW_USEDEFAULT,
  91.                   0,
  92.                   CW_USEDEFAULT,
  93.                   0,
  94.                   NULL,
  95.                   NULL,
  96.                   hInst,
  97.                   NULL);
  98.  
  99.     if ((!hwndFrame) || (!hwndMDIClient))
  100.     return FALSE;
  101.  
  102.     /* Load main menu accelerators */
  103.     if (!(hAccel = LoadAccelerators (hInst, IDMULTIPAD)))
  104.     return FALSE;
  105.  
  106.     /* Display the frame window */
  107.     ShowWindow (hwndFrame, nCmdShow);
  108.     UpdateWindow (hwndFrame);
  109.  
  110.     /* If the command line string is empty, nullify the pointer to it 
  111.     ** else copy command line into our data segment 
  112.     */
  113.     if ( lpCmdLine && !(*lpCmdLine))
  114.          pCmdLine = NULL;
  115.     else {
  116.         pCmdLine = (char *) LocalAlloc(LPTR, lstrlen(lpCmdLine) + 1);
  117.         if (pCmdLine)
  118.            lstrcpy(pCmdLine, lpCmdLine);
  119.     }
  120.  
  121.     /* Add the first MDI window */
  122.     AddFile (pCmdLine);
  123.  
  124.     /* if we allocated a buffer then free it */
  125.     if (pCmdLine)
  126.         LocalFree((LOCALHANDLE) pCmdLine);
  127.  
  128.     /* Default to minimized windows after the first. */
  129.     styleDefault = 0L;
  130.  
  131.     return TRUE;
  132.  
  133. }
  134.