Source code of Windows XP (NT5)
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.

171 lines
3.3 KiB

  1. #include <windows.h>
  2. #include <windowsx.h>
  3. #include <winspool.h>
  4. #include "faxutil.h"
  5. #include "faxreg.h"
  6. #include "faxcfgrs.h"
  7. #include "faxhelp.h"
  8. #include "faxcfg.h"
  9. #include "devmode.h"
  10. VOID
  11. LimitTextFields(
  12. HWND hDlg,
  13. INT *pLimitInfo
  14. )
  15. /*++
  16. Routine Description:
  17. Limit the maximum length for a number of text fields
  18. Arguments:
  19. hDlg - Specifies the handle to the dialog window
  20. pLimitInfo - Array of text field control IDs and their maximum length
  21. ID for the 1st text field, maximum length for the 1st text field
  22. ID for the 2nd text field, maximum length for the 2nd text field
  23. ...
  24. 0
  25. Note: The maximum length counts the NUL-terminator.
  26. Return Value:
  27. NONE
  28. --*/
  29. {
  30. while (*pLimitInfo != 0) {
  31. SendDlgItemMessage(hDlg, pLimitInfo[0], EM_SETLIMITTEXT, pLimitInfo[1]-1, 0);
  32. pLimitInfo += 2;
  33. }
  34. }
  35. PVOID
  36. MyGetPrinter(
  37. HANDLE hPrinter,
  38. DWORD level
  39. )
  40. /*++
  41. Routine Description:
  42. Wrapper function for GetPrinter spooler API
  43. Arguments:
  44. hPrinter - Identifies the printer in question
  45. level - Specifies the level of PRINTER_INFO_x structure requested
  46. Return Value:
  47. Pointer to a PRINTER_INFO_x structure, NULL if there is an error
  48. --*/
  49. {
  50. PBYTE pPrinterInfo = NULL;
  51. DWORD cbNeeded;
  52. if (!GetPrinter(hPrinter, level, NULL, 0, &cbNeeded) &&
  53. GetLastError() == ERROR_INSUFFICIENT_BUFFER &&
  54. (pPrinterInfo = MemAlloc(cbNeeded)) &&
  55. GetPrinter(hPrinter, level, pPrinterInfo, cbNeeded, &cbNeeded))
  56. {
  57. return pPrinterInfo;
  58. }
  59. DebugPrint((TEXT("GetPrinter failed: %d\n"), GetLastError()));
  60. MemFree(pPrinterInfo);
  61. return NULL;
  62. }
  63. INT
  64. DisplayMessageDialog(
  65. HWND hwndParent,
  66. UINT type,
  67. INT titleStrId,
  68. INT formatStrId,
  69. ...
  70. )
  71. /*++
  72. Routine Description:
  73. Display a message dialog box
  74. Arguments:
  75. hwndParent - Specifies a parent window for the error message dialog
  76. type - Specifies the type of message box to be displayed
  77. titleStrId - Title string (could be a string resource ID)
  78. formatStrId - Message format string (could be a string resource ID)
  79. ...
  80. Return Value:
  81. Same as the return value from MessageBox
  82. --*/
  83. {
  84. LPTSTR pTitle, pFormat, pMessage;
  85. INT result;
  86. va_list ap;
  87. pTitle = pFormat = pMessage = NULL;
  88. if ((pTitle = AllocStringZ(MAX_TITLE_LEN)) &&
  89. (pFormat = AllocStringZ(MAX_STRING_LEN)) &&
  90. (pMessage = AllocStringZ(MAX_MESSAGE_LEN)))
  91. {
  92. //
  93. // Load dialog box title string resource
  94. //
  95. if (titleStrId == 0)
  96. titleStrId = IDS_ERROR_CFGDLGTITLE;
  97. LoadString(ghInstance, titleStrId, pTitle, MAX_TITLE_LEN);
  98. //
  99. // Load message format string resource
  100. //
  101. LoadString(ghInstance, formatStrId, pFormat, MAX_STRING_LEN);
  102. //
  103. // Compose the message string
  104. //
  105. va_start(ap, formatStrId);
  106. wvsprintf(pMessage, pFormat, ap);
  107. va_end(ap);
  108. //
  109. // Display the message box
  110. //
  111. if (type == 0)
  112. type = MB_OK | MB_ICONERROR;
  113. result = MessageBox(hwndParent, pMessage, pTitle, type);
  114. } else {
  115. MessageBeep(MB_ICONHAND);
  116. result = 0;
  117. }
  118. MemFree(pTitle);
  119. MemFree(pFormat);
  120. MemFree(pMessage);
  121. return result;
  122. }