home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / winsock / globchat / client / dispatch.c < prev    next >
C/C++ Source or Header  |  1997-10-05  |  6KB  |  172 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-1997  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   dispatch.c
  9. //
  10. //  PURPOSE:  Implement the generic message and command dispatchers.
  11. //
  12. //
  13. //  FUNCTIONS:
  14. //    DispMessage - Call the function associated with a message.
  15. //    DispCommand - Call the function associated with a command.
  16. //    DispDefault - Call the appropriate default window procedure.
  17. //
  18. //  COMMENTS:
  19. //
  20.  
  21. #include <windows.h>            // required for all Windows applications
  22. #include <windowsx.h>
  23. #include <wsipx.h>              // IPX Sockets defs
  24. #include <wsnetbs.h>
  25. #include <nspapi.h>
  26. #include "globals.h"            // prototypes specific to this application
  27.  
  28. LRESULT DispDefault(EDWP, HWND, UINT, WPARAM, LPARAM);
  29.  
  30. //
  31. //  FUNCTION: DispMessage(LPMSDI, HWND, UINT, WPARAM, LPARAM)
  32. //
  33. //  PURPOSE: Call the function associated with a message.
  34. //
  35. //  PARAMETERS:
  36. //    lpmsdi - Structure containing the message dispatch information.
  37. //    hwnd - The window handle
  38. //    uMessage - The message number
  39. //    wparam - Message specific data
  40. //    lparam - Message specific data
  41. //
  42. //  RETURN VALUE:
  43. //    The value returned by the message function that was called.
  44. //
  45. //  COMMENTS:
  46. //    Runs the table of messages stored in lpmsdi->rgmsd searching
  47. //    for a message number that matches uMessage.  If a match is found,
  48. //    call the associated function.  Otherwise, call DispDefault to
  49. //    call the default function, if any, associated with the message
  50. //    structure.  In either case, return the value recieved from the
  51. //    message or default function.
  52. //
  53.  
  54. LRESULT DispMessage(LPMSDI lpmsdi,
  55.                     HWND   hwnd,
  56.                     UINT   uMessage,
  57.                     WPARAM wparam,
  58.                     LPARAM lparam)
  59. {
  60.     int  imsd = 0;
  61.  
  62.     MSD *rgmsd = lpmsdi->rgmsd;
  63.     int  cmsd  = lpmsdi->cmsd;
  64.  
  65.     for (imsd = 0; imsd < cmsd; imsd++)
  66.     {
  67.         if (rgmsd[imsd].uMessage == uMessage)
  68.             return rgmsd[imsd].pfnmsg(hwnd, uMessage, wparam, lparam);
  69.     }
  70.  
  71.     return DispDefault(lpmsdi->edwp, hwnd, uMessage, wparam, lparam);
  72. }
  73.  
  74. //
  75. //  FUNCTION: DispCommand(LPCMDI, HWND, WPARAM, LPARAM)
  76. //
  77. //  PURPOSE: Call the function associated with a command.
  78. //
  79. //  PARAMETERS:
  80. //    lpcmdi - Structure containing the command dispatch information.
  81. //    hwnd - The window handle
  82. //    GET_WM_COMMAND_ID(wparam, lparam) - Identifier of the menu item,
  83. //      control, or accelerator.
  84. //    GET_WM_COMMAND_CMD(wparam, lparam) - Notification code.
  85. //    GET_WM_COMMAND_HWND(wparam, lparam) - The control handle or NULL.
  86. //
  87. //  RETURN VALUE:
  88. //    The value returned by the command function that was called.
  89. //
  90. //  COMMENTS:
  91. //    Runs the table of commands stored in lpcmdi->rgcmd searching
  92. //    for a command number that matches wCommand.  If a match is found,
  93. //    call the associated function.  Otherwise, call DispDefault to
  94. //    call the default function, if any, associated with the command
  95. //    structure.  In either case, return the value recieved from the
  96. //    command or default function.
  97. //
  98.  
  99.  
  100. LRESULT DispCommand(LPCMDI lpcmdi,
  101.                     HWND   hwnd,
  102.                     WPARAM wparam,
  103.                     LPARAM lparam)
  104. {
  105.     LRESULT lRet = 0;
  106.     WORD    wCommand = GET_WM_COMMAND_ID(wparam, lparam);
  107.     int     icmd;
  108.  
  109.     CMD    *rgcmd = lpcmdi->rgcmd;
  110.     int     ccmd  = lpcmdi->ccmd;
  111.  
  112.     // Message packing of wparam and lparam have changed for Win32,
  113.     // so use the GET_WM_COMMAND macro to unpack the commnad
  114.  
  115.     for (icmd = 0; icmd < ccmd; icmd++)
  116.     {
  117.         if (rgcmd[icmd].wCommand == wCommand)
  118.         {
  119.             return rgcmd[icmd].pfncmd(hwnd,
  120.                                       wCommand,
  121.                                       GET_WM_COMMAND_CMD(wparam, lparam),
  122.                                       GET_WM_COMMAND_HWND(wparam, lparam));
  123.         }
  124.     }
  125.  
  126.     return DispDefault(lpcmdi->edwp, hwnd, WM_COMMAND, wparam, lparam);
  127. }
  128.  
  129.  
  130. //
  131. //  FUNCTION: DispDefault(EDWP, HWND, UINT, WPARAM, LPARAM)
  132. //
  133. //  PURPOSE: Call the appropriate default window procedure.
  134. //
  135. //  PARAMETERS:
  136. //    edwp - Enumerate specifying the appropriate default winow procedure.
  137. //    hwnd - The window handle
  138. //    uMessage - The message number
  139. //    wparam - Message specific data
  140. //    lparam - Message specific data
  141. //
  142. //  RETURN VALUE:
  143. //    If there is a default proc, return the value returned by the
  144. //    default proc.  Otherwise, return 0.
  145. //
  146. //  COMMENTS:
  147. //    Calls the default procedure associated with edwp using the specified
  148. //    parameters.
  149. //
  150.  
  151. LRESULT DispDefault(EDWP   edwp,
  152.                     HWND   hwnd,
  153.                     UINT   uMessage,
  154.                     WPARAM wparam,
  155.                     LPARAM lparam)
  156. {
  157.     switch (edwp)
  158.     {
  159.         case edwpNone:
  160.             return 0;
  161.         case edwpWindow:
  162.             return DefWindowProc(hwnd, uMessage, wparam, lparam);
  163.         case edwpDialog:
  164.             return DefDlgProc(hwnd, uMessage, wparam, lparam);
  165.         case edwpMDIFrame:
  166.             return DefFrameProc(hwnd, hwndMDIGlobCl, uMessage, wparam, lparam);
  167.         case edwpMDIChild:
  168.             return DefMDIChildProc(hwnd, uMessage, wparam, lparam);
  169.     }
  170.     return 0;
  171. }
  172.