home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / SAMPLES / MULTIPAD / MPINIT.C_ / MPINIT.C
Encoding:
C/C++ Source or Header  |  1993-02-08  |  4.4 KB  |  147 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.  
  16. #include "multipad.h"
  17. #include "commdlg.h"
  18.  
  19. PRINTDLG pd;                  /* Common print dialog structure */
  20.  
  21. char szFrame[] = "mpframe";   /* Class name for "frame" window */
  22. char szChild[] = "mpchild";   /* Class name for MDI window     */
  23.  
  24. /****************************************************************************
  25.  *                                        *
  26.  *  FUNCTION   : InitializeApplication ()                    *
  27.  *                                        *
  28.  *  PURPOSE    : Sets up the class data structures and does a one-time        *
  29.  *         initialization of the app by registering the window classes*
  30.  *                                        *
  31.  *  RETURNS    : TRUE  - If RegisterClass() was successful for both classes.*
  32.  *         FALSE - otherwise.                        *
  33.  *                                        *
  34.  ****************************************************************************/
  35.  
  36. BOOL FAR PASCAL InitializeApplication()
  37. {
  38.     WNDCLASS    wc;
  39.  
  40.     /* Register the frame class */
  41.     wc.style         = 0;
  42.     wc.lpfnWndProc   = MPFrameWndProc;
  43.     wc.cbClsExtra    = 0;
  44.     wc.cbWndExtra    = 0;
  45.     wc.hInstance     = hInst;
  46.     wc.hIcon         = LoadIcon(hInst,IDMULTIPAD);
  47.     wc.hCursor         = LoadCursor(NULL,IDC_ARROW);
  48.     wc.hbrBackground = COLOR_APPWORKSPACE+1;
  49.     wc.lpszMenuName  = IDMULTIPAD;
  50.     wc.lpszClassName = szFrame;
  51.  
  52.     if (!RegisterClass (&wc) )
  53.     return FALSE;
  54.  
  55.     /* Register the MDI child class */
  56.     wc.lpfnWndProc   = MPMDIChildWndProc;
  57.     wc.hIcon         = LoadIcon(hInst,IDNOTE);
  58.     wc.lpszMenuName  = NULL;
  59.     wc.cbWndExtra    = CBWNDEXTRA;
  60.     wc.lpszClassName = szChild;
  61.  
  62.     /* fill in non-variant fields of PRINTDLG struct. */
  63.  
  64.     pd.lStructSize    = sizeof(PRINTDLG);
  65.     pd.hDevMode       = NULL;
  66.     pd.hDevNames      = NULL;
  67.     pd.Flags          = PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS;
  68.     pd.nCopies        = 1;
  69.  
  70.    
  71.    if (!RegisterClass(&wc))
  72.     return FALSE;
  73.  
  74.     return TRUE;
  75.  
  76. }
  77.  
  78. /****************************************************************************
  79.  *                                        *
  80.  *  FUNCTION   : InitializeInstance ()                        *
  81.  *                                        *
  82.  *  PURPOSE    : Performs a per-instance initialization of MultiPad. It     *
  83.  *         also creates the frame and an MDI window.            *
  84.  *                                        *
  85.  *  RETURNS    : TRUE  - If initialization was successful.            *
  86.  *         FALSE - otherwise.                        *
  87.  *                                        *
  88.  ****************************************************************************/
  89. BOOL FAR PASCAL InitializeInstance(LPSTR lpCmdLine, WORD nCmdShow)
  90. {
  91.     extern HWND  hwndMDIClient;
  92.     char     sz[80], *pCmdLine;
  93.  
  94.     /* Get the base window title */
  95.     LoadString (hInst, IDS_APPNAME, sz, sizeof(sz));
  96.  
  97.     /* Create the frame */
  98.     hwndFrame = CreateWindow (szFrame,
  99.                   sz,
  100.                   WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  101.                   CW_USEDEFAULT,
  102.                   0,
  103.                   CW_USEDEFAULT,
  104.                   0,
  105.                   NULL,
  106.                   NULL,
  107.                   hInst,
  108.                   NULL);
  109.  
  110.     if ((!hwndFrame) || (!hwndMDIClient))
  111.     return FALSE;
  112.  
  113.     pd.hwndOwner = hwndFrame;
  114.  
  115.    /* Load main menu accelerators */
  116.     if (!(hAccel = LoadAccelerators (hInst, IDMULTIPAD)))
  117.     return FALSE;
  118.  
  119.     /* Display the frame window */
  120.     ShowWindow (hwndFrame, nCmdShow);
  121.     UpdateWindow (hwndFrame);
  122.  
  123.     /* If the command line string is empty, nullify the pointer to it 
  124.     ** else copy command line into our data segment 
  125.     */
  126.     if ( lpCmdLine && !(*lpCmdLine))
  127.          pCmdLine = NULL;
  128.     else {
  129.         pCmdLine = (char *) LocalAlloc(LPTR, lstrlen(lpCmdLine) + 1);
  130.         if (pCmdLine)
  131.            lstrcpy(pCmdLine, lpCmdLine);
  132.     }
  133.  
  134.     /* Add the first MDI window */
  135.     AddFile (pCmdLine);
  136.  
  137.     /* if we allocated a buffer then free it */
  138.     if (pCmdLine)
  139.         LocalFree((LOCALHANDLE) pCmdLine);
  140.  
  141.     /* Default to minimized windows after the first. */
  142.     styleDefault = 0L;
  143.  
  144.     return TRUE;
  145.  
  146. }
  147.