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.

113 lines
2.3 KiB

  1. #include "precomp.h"
  2. #include "resource.h"
  3. #include "confwnd.h"
  4. #include "confapi.h"
  5. #include "ConfUtil.h"
  6. HWND GetMsgBoxParent(void)
  7. {
  8. return (_Module.IsUIVisible() ? ::GetMainWindow() : HWND_DESKTOP );
  9. }
  10. VOID PostConfMsgBox(UINT uStringID)
  11. {
  12. ::PostMessage(::GetHiddenWindow(), WM_CONF_MSG_BOX, uStringID, 0);
  13. }
  14. static const UINT MAX_CONFMSGBOX_STRING = 1024;
  15. int ConfMsgBox(HWND hwndParent, LPCTSTR pcszMsg, UINT uType)
  16. {
  17. if(_Module.InitControlMode())
  18. {
  19. // Return a reasonable value
  20. // TODO: Look at MB_DEFBUTTON1
  21. switch (uType & 0x0F)
  22. {
  23. case MB_YESNOCANCEL:
  24. case MB_YESNO:
  25. return IDYES;
  26. case MB_OK:
  27. case MB_OKCANCEL:
  28. default:
  29. return IDOK;
  30. }
  31. }
  32. TCHAR szTitleBuf[MAX_PATH];
  33. TCHAR szMsgBuf[MAX_CONFMSGBOX_STRING];
  34. LPTSTR pszTrueMsg = (LPTSTR) pcszMsg;
  35. if (0 == HIWORD(pcszMsg))
  36. {
  37. // The string pointer is actually a resource id:
  38. if (::LoadString( ::GetInstanceHandle(),
  39. PtrToUint(pcszMsg),
  40. szMsgBuf,
  41. CCHMAX(szMsgBuf)))
  42. {
  43. pszTrueMsg = szMsgBuf;
  44. }
  45. else
  46. {
  47. pszTrueMsg = NULL;
  48. }
  49. }
  50. // The string pointer is actually a resource id:
  51. ::LoadString( ::GetInstanceHandle(),
  52. IDS_MSGBOX_TITLE,
  53. szTitleBuf,
  54. CCHMAX(szTitleBuf));
  55. ASSERT(pszTrueMsg);
  56. return ::MessageBox(hwndParent,
  57. pszTrueMsg,
  58. szTitleBuf,
  59. uType);
  60. }
  61. VOID DisplayMsgIdsParam(int ids, LPCTSTR pcsz)
  62. {
  63. if (!_Module.InitControlMode())
  64. {
  65. TCHAR szFormat[MAX_CONFMSGBOX_STRING];
  66. int nLength = ::LoadString(::GetInstanceHandle(), ids, szFormat, CCHMAX(szFormat));
  67. ASSERT(0 != nLength);
  68. LPTSTR pszMsg = new TCHAR[nLength + (FEmptySz(pcsz) ? 1 : lstrlen(pcsz))];
  69. if (NULL == pszMsg)
  70. {
  71. ERROR_OUT(("DisplayMsgIdsParam - out of memory"));
  72. return;
  73. }
  74. // Format the message
  75. wsprintf(pszMsg, szFormat, pcsz);
  76. if (!::PostMessage(::GetHiddenWindow(), WM_NM_DISPLAY_MSG,
  77. (WPARAM) MB_ICONINFORMATION | MB_SETFOREGROUND | MB_OK, (LPARAM) pszMsg))
  78. {
  79. delete pszMsg;
  80. ERROR_OUT(("DisplayMsgIdsParam - out of memory"));
  81. }
  82. }
  83. }
  84. int DisplayMsg(LPTSTR pszMsg, UINT uType)
  85. {
  86. TCHAR szTitle[MAX_PATH];
  87. FLoadString(IDS_MSGBOX_TITLE, szTitle, CCHMAX(szTitle));
  88. int id = ::MessageBox(GetMsgBoxParent(), pszMsg, szTitle, uType);
  89. delete pszMsg;
  90. return id;
  91. }
  92. VOID DisplayErrMsg(INT_PTR ids)
  93. {
  94. ConfMsgBox(::GetMainWindow(), (LPCTSTR) ids, MB_OK | MB_SETFOREGROUND | MB_ICONERROR);
  95. }