home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / BLANDMDI.PAK / MDICHILD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  5.1 KB  |  208 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   mdichild.c
  9. //
  10. //  PURPOSE:
  11. //    To implement the basic mdi child commands.
  12. //
  13. //  FUNCTIONS:
  14. //    InitMDIChild - To register the MDI child window class.
  15. //    MDIChildWndProc - Processes messages for MDI child windows.
  16. //    MsgMCCommand - Handle the WM_COMMAND messages for mdi children.
  17. //
  18. //  COMMENTS:
  19. //
  20. //
  21. //  SPECIAL INSTRUCTIONS: N/A
  22. //
  23.  
  24. #include <windows.h>            // required for all Windows applications
  25. #include <windowsx.h>
  26. #ifdef WIN16
  27. #include "win16ext.h"           // required only for win16 applications
  28. #endif
  29. #include "globals.h"            // prototypes specific to this application
  30. #include "resource.h"
  31.  
  32.  
  33. static MSD rgmsd[] =
  34. {
  35.     {WM_COMMAND,    MsgMCCommand},
  36.     {WM_DESTROY,    MsgMCDestroy}
  37. };
  38.  
  39. MSDI msdiChild =
  40. {
  41.     sizeof(rgmsd) / sizeof(MSD),
  42.     rgmsd,
  43.     edwpMDIChild
  44. };
  45.  
  46. static CMD rgcmd[] =
  47. {
  48.     {0, NULL}
  49. };
  50.  
  51. CMDI cmdiChild =
  52. {
  53.     sizeof(rgcmd) / sizeof(CMD),
  54.     rgcmd,
  55.     edwpMDIChild
  56. };
  57.  
  58.  
  59. // Module specific globals
  60.  
  61. char szChildName[] = "MdiChild";
  62.  
  63. //
  64. //  FUNCTION: InitMDIChild(HINSTANCE)
  65. //
  66. //  PURPOSE: To register the MDI child window class.
  67. //
  68. //  PARAMETERS:
  69. //    hinst - The instance of the application used to register the class.
  70. //
  71. //  RETURN VALUE:
  72. //    TRUE - Succeeded in registering the class.
  73. //    FALSE - Failed to register the class.
  74. //
  75. //  COMMENTS:
  76. //
  77. //
  78.  
  79. BOOL InitMDIChild(HINSTANCE hinst)
  80. {
  81.     #ifdef WIN16
  82.     WNDCLASS wc;
  83.     #else
  84.     WNDCLASSEX wc;
  85.     #endif
  86.  
  87.     #ifndef WIN16
  88.     wc.cbSize        = sizeof(WNDCLASSEX);
  89.     wc.hIconSm       = LoadImage(hinst,            // Load small icon image
  90.                                  MAKEINTRESOURCE(IDI_CHILDICON),
  91.                                  IMAGE_ICON,
  92.                                  16, 16,
  93.                                  0);
  94.     #endif
  95.     wc.style         = 0;
  96.     wc.lpfnWndProc   = (WNDPROC)MDIChildWndProc;
  97.     wc.cbClsExtra    = 0;
  98.     wc.cbWndExtra    = 0;
  99.     wc.hInstance     = hinst;                      // Owner of this class
  100.     wc.hIcon         = LoadIcon(hinst, MAKEINTRESOURCE(IDI_CHILDICON));
  101.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  102.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color
  103.     wc.lpszMenuName  = NULL;
  104.     wc.lpszClassName = szChildName;
  105.  
  106.     #ifdef WIN16
  107.     if (!RegisterClass(&wc))
  108.     {
  109.         return FALSE;
  110.     }
  111.     #else
  112.     if (!RegisterClassEx(&wc))
  113.     {
  114.         //Assume we are running on NT where RegisterClassEx() is
  115.         //not implemented, so let's try calling RegisterClass().
  116.  
  117.         if (!RegisterClass((LPWNDCLASS)&wc.style))
  118.             return FALSE;
  119.     }
  120.     #endif
  121.  
  122.     return TRUE;
  123. }
  124.  
  125. //
  126. //  FUNCTION: MDIChildWndProc(HWND, UINT, WPARAM, LPARAM)
  127. //
  128. //  PURPOSE:  Processes messages for MDI child windows.
  129. //
  130. //  PARAMETERS:
  131. //    hwnd     - window handle
  132. //    uMessage - message number
  133. //    wparam   - additional information (dependant of message number)
  134. //    lparam   - additional information (dependant of message number)
  135. //
  136. //  RETURN VALUE:
  137. //    Depends on the message number.
  138. //
  139. //  COMMENTS:
  140. //    Uses the combination of the message structure defined in mditable.c
  141. //    and the DispMessage function defined in WndProc.c to handle all
  142. //    messages directed to an MDI child window.
  143. //
  144.  
  145. LRESULT CALLBACK MDIChildWndProc(HWND hwnd,
  146.                                  UINT uMessage,
  147.                                  WPARAM wparam,
  148.                                  LPARAM lparam)
  149. {
  150.     return DispMessage( &msdiChild, hwnd, uMessage, wparam, lparam );
  151. }
  152.  
  153.  
  154. //
  155. //  FUNCTION: MsgMCCommand(HWND, UINT, WPARAM, LPARAM)
  156. //
  157. //  PURPOSE: Handle the WM_COMMAND messages for mdi children.
  158. //
  159. //  PARAMETERS:
  160. //    hwnd     - window handle
  161. //    uMessage - message number (Unused)
  162. //    GET_WM_COMMAND_ID(wparam,lparam)   - Command identifier
  163. //    GET_WM_COMMAND_HWND(wparam,lparam) - Control handle
  164. //
  165. //  RETURN VALUE:
  166. //
  167. //  COMMENTS:
  168. //    Uses the combination of the command structure defined in mditable.c
  169. //    and the DispCommand function defined in WndProc.c to handle all
  170. //    commands directed to an MDI child window.
  171. //
  172. //
  173.  
  174. #pragma argsused
  175. LRESULT MsgMCCommand(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
  176. {
  177.     return DispCommand(&cmdiChild, hwnd, wparam, lparam);
  178. }
  179.  
  180.  
  181. //
  182. //  FUNCTION: MsgMCDestroy(HWND, UINT, WPARAM, LPARAM)
  183. //
  184. //  PURPOSE:
  185. //
  186. //  PARAMETERS:
  187. //    hwnd - The window handing the message.
  188. //    uMessage - The message number. (unused).
  189. //    wparam - Message specific data (unused).
  190. //    lparam - Message specific data (unused).
  191. //
  192. //  RETURN VALUE:
  193. //    Always returns 0 - message handled.
  194. //
  195. //  COMMENTS:
  196. //
  197. //
  198.  
  199. #pragma argsused
  200. LRESULT MsgMCDestroy(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
  201. {
  202.      cOpen -= 1;
  203.  
  204.      return 0;
  205. }
  206.  
  207.  
  208.