home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / activedocument / dfv / message.cxx < prev    next >
C/C++ Source or Header  |  1995-02-13  |  4KB  |  122 lines

  1. //+---------------------------------------------------------------------------
  2. //
  3. //  Microsoft Windows
  4. //  Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. //  File:       message.cxx
  7. //
  8. //  Contents:   Helper functions for popup message boxes.
  9. //
  10. //  Classes:
  11. //
  12. //  Functions:  MessageBoxFromSringIds
  13. //
  14. //  History:    6-24-94   stevebl   Created
  15. //
  16. //----------------------------------------------------------------------------
  17.  
  18. #include <windows.h>
  19. #include "message.h"
  20.  
  21. //+---------------------------------------------------------------------------
  22. //
  23. //  Function:   MessageBoxFromStringIds
  24. //
  25. //  Synopsis:   Displays a simple message box taking its text from a string
  26. //              table instead of from user allocated strings.
  27. //
  28. //  Arguments:  [hwndOwner]      - window handle for the message box's owner
  29. //              [hinst]          - instance associated with the string table
  30. //              [idText]         - string id for the box's text string
  31. //              [idTitle]        - string id for the box's title string
  32. //              [fuStyle]        - style of message box
  33. //                                 (see Windows function MessageBox for styles)
  34. //
  35. //  Returns:    result from MessageBox
  36. //
  37. //  History:    6-24-94   stevebl   Created
  38. //
  39. //  Notes:      Each string is limited to MAX_STRING_LENGTH characters.
  40. //
  41. //----------------------------------------------------------------------------
  42.  
  43. int MessageBoxFromStringIds(
  44.     const HWND hwndOwner,
  45.     const HINSTANCE hinst,
  46.     const UINT idText,
  47.     const UINT idTitle,
  48.     const UINT fuStyle)
  49. {
  50.     int iReturn = 0;
  51.     TCHAR szTitle[MAX_STRING_LENGTH];
  52.     TCHAR szText[MAX_STRING_LENGTH];
  53.     if (LoadString(hinst, idTitle, szTitle, MAX_STRING_LENGTH))
  54.     {
  55.         if (LoadString(hinst, idText, szText, MAX_STRING_LENGTH))
  56.         {
  57.             iReturn = MessageBox(
  58.                 hwndOwner,
  59.                 szText,
  60.                 szTitle,
  61.                 fuStyle);
  62.         }
  63.     }
  64.     return(iReturn);
  65. }
  66.  
  67. //+---------------------------------------------------------------------------
  68. //
  69. //  Function:   MessageBoxFromStringIdsAndArgs
  70. //
  71. //  Synopsis:   Creates a message box from a pair of string IDs similar
  72. //              to MessageBoxFromStringIds.  The principle difference
  73. //              is that idFormat is an ID for a string which is a printf
  74. //              format string suitable for passing to wsprintf.
  75. //              The variable argument list is combined with the format
  76. //              string to create the text of the message box.
  77. //
  78. //  Arguments:  [hwndOwner] - window handle for the message box's owner
  79. //              [hinst]     - instance associated with the string table
  80. //              [idFormat]  - string id for the format of the box's text
  81. //              [idTitle]   - string id for the box's title string
  82. //              [fuStyle]   - style of the dialog box
  83. //              [...]       - argument list for text format string
  84. //
  85. //  Returns:    result from MessageBox
  86. //
  87. //  History:    6-24-94   stevebl   Created
  88. //
  89. //  Notes:      Neither the composed text string nor the title must be
  90. //              longer than MAX_STRING_LENGTH characters.
  91. //
  92. //----------------------------------------------------------------------------
  93.  
  94. int MessageBoxFromStringIdsAndArgs(
  95.     const HWND hwndOwner,
  96.     const HINSTANCE hinst,
  97.     const UINT idFormat,
  98.     const UINT idTitle,
  99.     const UINT fuStyle, ...)
  100. {
  101.     int iReturn = 0;
  102.     va_list arglist;
  103.     va_start(arglist, fuStyle);
  104.     TCHAR szTitle[MAX_STRING_LENGTH];
  105.     TCHAR szText[MAX_STRING_LENGTH];
  106.     TCHAR szFormat[MAX_STRING_LENGTH];
  107.     if (LoadString(hinst, idTitle, szTitle, MAX_STRING_LENGTH))
  108.     {
  109.         if (LoadString(hinst, idFormat, szFormat, MAX_STRING_LENGTH))
  110.         {
  111.             wvsprintf(szText, szFormat, arglist);
  112.             iReturn = MessageBox(
  113.                 hwndOwner,
  114.                 szText,
  115.                 szTitle,
  116.                 fuStyle);
  117.         }
  118.     }
  119.     return(iReturn);
  120. }
  121.  
  122.