home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / SAMPLES / PENPAD / PPINIT.C_ / PPINIT.C
Encoding:
C/C++ Source or Header  |  1993-02-08  |  4.0 KB  |  132 lines

  1. /***************************************************************************
  2.  *                                       *
  3.  *  MODULE    : PpInit.c                           *
  4.  *                                       *
  5.  *  PURPOSE    : Contains initialization code for penpad.           *
  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 penpad. Creates   *
  12.  *                        the "frame" and MDI client.    *
  13.  *                                       *
  14.  ***************************************************************************/
  15. #include "penpad.h"
  16.  
  17. char szFrame[] = "ppframe";   /* Class name for "frame" window */
  18. char szChild[] = "ppchild";   /* 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   = PPFrameWndProc;
  39.     wc.cbClsExtra    = 0;
  40.     wc.cbWndExtra    = 0;
  41.     wc.hInstance     = hInst;
  42.     wc.hIcon         = LoadIcon(hInst,IDPENPAD);
  43.     wc.hCursor         = LoadCursor(NULL,IDC_ARROW);
  44.     wc.hbrBackground = COLOR_APPWORKSPACE+1;
  45.     wc.lpszMenuName  = IDPENPAD;
  46.     wc.lpszClassName = szFrame;
  47.  
  48.     if (!RegisterClass (&wc) )
  49.     return FALSE;
  50.  
  51.     /* Register the MDI child class */
  52.     wc.lpfnWndProc   = PPMDIChildWndProc;
  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.  
  81.     /* Get the base window title */
  82.     LoadString (hInst, IDS_APPNAME, sz, sizeof(sz));
  83.  
  84.     /* Create the frame */
  85.     hwndFrame = CreateWindow (szFrame,
  86.                   sz,
  87.                   WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  88.                   CW_USEDEFAULT,
  89.                   0,
  90.                   CW_USEDEFAULT,
  91.                   0,
  92.                   NULL,
  93.                   NULL,
  94.                   hInst,
  95.                   NULL);
  96.  
  97.     if ((!hwndFrame) || (!hwndMDIClient))
  98.     return FALSE;
  99.  
  100.     /* Load main menu accelerators */
  101.     if (!(hAccel = LoadAccelerators (hInst, IDPENPAD)))
  102.     return FALSE;
  103.  
  104.     /* Display the frame window */
  105.     ShowWindow (hwndFrame, nCmdShow);
  106.     UpdateWindow (hwndFrame);
  107.  
  108.     /* If the command line string is empty, nullify the pointer to it 
  109.     ** else copy command line into our data segment 
  110.     */
  111.     if ( lpCmdLine && !(*lpCmdLine))
  112.          pCmdLine = NULL;
  113.     else {
  114.         pCmdLine = (char *) LocalAlloc(LPTR, lstrlen(lpCmdLine) + 1);
  115.         if (pCmdLine)
  116.            lstrcpy(pCmdLine, lpCmdLine);
  117.     }
  118.  
  119.     /* Add the first MDI window */
  120.     AddFile (pCmdLine);
  121.  
  122.     /* if we allocated a buffer then free it */
  123.     if (pCmdLine)
  124.         LocalFree((LOCALHANDLE) pCmdLine);
  125.  
  126.     /* Default to minimized windows after the first. */
  127.     styleDefault = 0L;
  128.  
  129.     return TRUE;
  130.  
  131. }
  132.