Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
3.2 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. bkmem.c
  5. Abstract:
  6. Resource manipulation routines for online books program.
  7. Author:
  8. Ted Miller (tedm) 5-Jan-1995
  9. Revision History:
  10. --*/
  11. #include "books.h"
  12. PWSTR
  13. MyLoadString(
  14. IN UINT StringId
  15. )
  16. /*++
  17. Routine Description:
  18. Load a string from the application's string table resource
  19. and place it into a buffer.
  20. Arguments:
  21. StringId - supplies the string table id of the string to be retreived.
  22. Return Value:
  23. Pointer to a buffer containing the string. If any error
  24. occured the buffer will be empty.
  25. The caller can free the buffer via MyFree when done with it.
  26. --*/
  27. {
  28. WCHAR buf[4096];
  29. int i;
  30. PWSTR p;
  31. i = LoadString(hInst,StringId,buf,sizeof(buf)/sizeof(buf[0]));
  32. if(!i) {
  33. buf[0] = 0;
  34. }
  35. return DupString(buf);
  36. }
  37. int
  38. MessageBoxFromMessage(
  39. IN HWND Owner,
  40. IN UINT MessageId,
  41. IN UINT CaptionStringId,
  42. IN UINT Style,
  43. ...
  44. )
  45. /*++
  46. Routine Description:
  47. Display a message box whose text is a formatted message and whose caption
  48. is a string in the application's string resources.
  49. Arguments:
  50. Owner - supplied handle of owner window
  51. MessageId - supplies id of message in message table resources
  52. CaptionStringId - supplies id of string in string resources. If this
  53. value is 0 the default ("Error") is used.
  54. Style - supplies style flags to be passed to MessageBox
  55. Return Value:
  56. Return value from MessageBox.
  57. --*/
  58. {
  59. PWSTR Text,Caption;
  60. va_list arglist;
  61. DWORD d;
  62. int i;
  63. va_start(arglist,Style);
  64. d = FormatMessage(
  65. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE,
  66. hInst,
  67. MessageId,
  68. 0,
  69. (LPTSTR)&Text,
  70. 0,
  71. &arglist
  72. );
  73. va_end(arglist);
  74. if(!d) {
  75. OutOfMemory();
  76. }
  77. Caption = CaptionStringId ? MyLoadString(CaptionStringId) : NULL;
  78. i = MessageBox(Owner,Text,Caption,Style);
  79. if(Caption) {
  80. MyFree(Caption);
  81. }
  82. LocalFree(Text);
  83. return(i);
  84. }
  85. PWSTR
  86. RetreiveMessage(
  87. IN UINT MessageId,
  88. ...
  89. )
  90. /*++
  91. Routine Description:
  92. Retreive and format a message from the application's message resources.
  93. Arguments:
  94. MessageId - supplies the message id of the message to be
  95. retreived and formatted.
  96. ... - additional arguments supply strings to be inserted into the
  97. message as it is formatted.
  98. Return Value:
  99. Pointer to a buffer containing the string. If any error
  100. occured the buffer will be empty.
  101. The caller can free the buffer via MyFree when done with it.
  102. --*/
  103. {
  104. va_list arglist;
  105. DWORD d;
  106. PWSTR p,q;
  107. va_start(arglist,MessageId);
  108. d = FormatMessage(
  109. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE,
  110. hInst,
  111. MessageId,
  112. 0,
  113. (LPTSTR)&p,
  114. 0,
  115. &arglist
  116. );
  117. va_end(arglist);
  118. if(!d) {
  119. OutOfMemory();
  120. }
  121. //
  122. // Move the string to a buffer allocated with MyAlloc so the caller
  123. // can use MyFree instead of LocalFree (to avoid confusion).
  124. //
  125. q = DupString(p);
  126. LocalFree((HLOCAL)p);
  127. return(q);
  128. }