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

  1. /*
  2.  *
  3.  *  MODULE   : BlandIni.c
  4.  *
  5.  *  PURPOSE  : Contains initialization code for BlandMDI.
  6.  *
  7.  *  FUNCTIONS:
  8.  *
  9.  *      InitializeApplication() - Sets up Class data structure
  10.  *                                and registers window class.
  11.  *
  12.  *      InitializeInstance ()   - Does a per-instance initialization
  13.  *                                of BlandMDI. Creates the "frame"
  14.  *                                and MDI client.
  15.  *
  16.  *      MakeNewChild ()         - Creates a new MDI child window
  17.  *
  18.  * Copyright 1991 Microsoft Corporation. All rights reserved.
  19.  */
  20.  
  21. /*------------------------  #includes  --------------------------------*/
  22.  
  23. #include "BlandMDI.h"
  24.  
  25.  
  26. /*------------------------  global variables  -------------------------*/
  27.  
  28. char szFrame[] = "bland frame";   // Class name for "frame" window
  29. char szChild[] = "bland child";   // Class name for MDI window
  30.  
  31.  
  32. /*--------------------- InitializeApplication  -------------------------*/
  33. /*
  34.  *
  35.  *  FUNCTION   : InitializeApplication ()
  36.  *
  37.  *  PURPOSE    : Sets up the class data structures and does a one-time
  38.  *               initialization of the app by registering the window classes
  39.  *
  40.  *  RETURNS    : TRUE  - If RegisterClass() was successful for both classes.
  41.  *               FALSE - otherwise.
  42.  *
  43.  */
  44.  
  45. BOOL FAR PASCAL InitializeApplication()
  46. {
  47.     WNDCLASS  wc;
  48.  
  49.     // Register the frame class 
  50.     wc.style         = 0;
  51.     wc.lpfnWndProc   = BlandFrameWndProc;
  52.     wc.cbClsExtra    = 0;
  53.     wc.cbWndExtra    = 0;
  54.     wc.hInstance     = hInst;
  55.     wc.hIcon         = LoadIcon(hInst, IDBLANDFRAME);
  56.     wc.hCursor       = LoadCursor(NULL,IDC_ARROW);
  57.     wc.hbrBackground = COLOR_APPWORKSPACE+1;
  58.     wc.lpszMenuName  = IDBLANDMENU;
  59.     wc.lpszClassName = szFrame;
  60.  
  61.     if (RegisterClass (&wc))
  62.       {
  63.       // Register the MDI child class 
  64.       wc.lpfnWndProc   = BlandMDIChildWndProc;
  65.       wc.hIcon         = LoadIcon(hInst,IDBLANDCHILD);
  66.       wc.lpszMenuName  = NULL;
  67.       wc.cbWndExtra    = CBWNDEXTRA;
  68.       wc.lpszClassName = szChild;
  69.  
  70.       if (RegisterClass(&wc))
  71.         return TRUE;
  72.       }
  73.  
  74.     return FALSE;
  75. }
  76.  
  77.  
  78. /*----------------------  InitializeInstance  --------------------------*/
  79. /*
  80.  *
  81.  *  FUNCTION   : InitializeInstance ()
  82.  *
  83.  *  PURPOSE    : Performs a per-instance initialization of BlandMDI. It
  84.  *               also creates the frame and one MDI child window.
  85.  *
  86.  *  RETURNS    : TRUE  - If initialization was successful.
  87.  *               FALSE - otherwise.
  88.  *
  89.  */
  90.  
  91.  
  92. BOOL FAR PASCAL InitializeInstance(LPSTR lpCmdLine, WORD nCmdShow)
  93. {
  94.     extern HWND   hwndMDIClient;
  95.        char   sz[80];
  96.  
  97.     // Get the base window title
  98.     LoadString (hInst, IDS_APPNAME, sz, sizeof(sz));
  99.  
  100.     // Create the frame 
  101.     // MDI Client window is created in frame's WM_CREATE case
  102.     hwndFrame = CreateWindow (szFrame,
  103.             sz,
  104.             WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  105.             CW_USEDEFAULT,
  106.             0,
  107.             CW_USEDEFAULT,
  108.             0,
  109.             NULL,
  110.             NULL,
  111.             hInst,
  112.             NULL);
  113.  
  114.     if (hwndFrame && hwndMDIClient)
  115.         {
  116.         // Display the frame window 
  117.         ShowWindow (hwndFrame, nCmdShow);
  118.         UpdateWindow (hwndFrame);
  119.  
  120.         // Make the first MDI child window 
  121.         MakeNewChild ("Initial Window");
  122.         return TRUE;
  123.         }
  124.  
  125.     return FALSE;
  126. }
  127.  
  128.  
  129. /*----------------   MakeNewChild  -----------------------------*/
  130. /*
  131.  *
  132.  *  FUNCTION   : MakeNewChild (lpName)
  133.  *
  134.  *  PURPOSE    : Creates a new MDI child window.
  135.  *
  136.  *  RETURNS    : HWND  - A handle to the new window.
  137.  *
  138.  */
  139.  
  140. HWND FAR PASCAL MakeNewChild(char *pName)
  141. {
  142.     HWND            hwnd;
  143.     char            sz[160];
  144.     MDICREATESTRUCT mcs;
  145.  
  146.     if (!pName)
  147.         {
  148.         // pName parameter is NULL -- load the "Untitled" string 
  149.         // from STRINGTABLE
  150.         LoadString (hInst, IDS_UNTITLED, sz, sizeof(sz));
  151.         mcs.szTitle = (LPSTR)sz;
  152.         }
  153.     else
  154.         {
  155.         mcs.szTitle = (LPSTR)pName; /* Fully qualified pathname*/
  156.         }
  157.  
  158.     mcs.szClass    = szChild;
  159.     mcs.hOwner     = hInst;
  160.     mcs.x = mcs.cx = CW_USEDEFAULT;  // Use the default size for the window
  161.     mcs.y = mcs.cy = CW_USEDEFAULT;
  162.     mcs.style      = styleDefault;   // Set the style DWORD of the window
  163.                                      // to default
  164.     // tell the MDI Client to create the child 
  165.     hwnd = (WORD)SendMessage (hwndMDIClient,
  166.                               WM_MDICREATE,
  167.                               0,
  168.                               (LONG)(LPMDICREATESTRUCT)&mcs);
  169.     ShowWindow(hwnd, SW_SHOW);
  170.  
  171.     return hwnd;
  172. }
  173.