home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / vrac / mpad32.zip / MPINIT.C < prev    next >
C/C++ Source or Header  |  1994-04-15  |  6KB  |  148 lines

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