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.

216 lines
5.1 KiB

  1. #include "stdafx.h"
  2. #include <stdarg.h>
  3. #include "pbrush.h"
  4. #include "pbrusfrm.h"
  5. #include "pbrusvw.h"
  6. #include "minifwnd.h"
  7. #include "cmpmsg.h"
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static CHAR BASED_CODE THIS_FILE[] = __FILE__;
  11. #endif
  12. #include "memtrace.h"
  13. //
  14. //
  15. // CmpCenterParent retrieves a window to which a modal dialog should
  16. // be centered (relative center).
  17. //
  18. // NOTE: The return value may be temporary!
  19. //
  20. CWnd* CmpCenterParent()
  21. {
  22. CWnd* pPopupWnd = AfxGetMainWnd();;
  23. ASSERT(pPopupWnd != NULL);
  24. if (pPopupWnd->IsKindOf(RUNTIME_CLASS(CMiniFrmWnd)))
  25. {
  26. // don't center relative to mini-frame windows
  27. CWnd* pParentWnd = pPopupWnd->GetParent();
  28. // instead use parent or main window...
  29. if (pParentWnd != NULL)
  30. pPopupWnd = pParentWnd;
  31. else
  32. pPopupWnd = theApp.m_pMainWnd;
  33. }
  34. return pPopupWnd;
  35. }
  36. //
  37. // composer message box, same interface as windows, but you give
  38. // string id's not strings
  39. //
  40. // example: CmpMessageBox( IDS_OUTOFMEMORY, IDS_ERROR, MB_OK );
  41. //
  42. int CmpMessageBox( WORD wTextStringID, // string id of text
  43. WORD wCaptionID, // string id of caption
  44. UINT nType ) // same as message box
  45. {
  46. TCHAR FAR* lpText;
  47. TCHAR FAR* lpCaption;
  48. CString sText, sCaption;
  49. if( wCaptionID == CMPNOSTRING )
  50. lpCaption = NULL;
  51. else
  52. {
  53. VERIFY( sCaption.LoadString( wCaptionID ) );
  54. lpCaption = (TCHAR FAR*)(const TCHAR *)sCaption;
  55. }
  56. if( wTextStringID == CMPNOSTRING )
  57. lpText = TEXT("");
  58. else
  59. {
  60. VERIFY( sText.LoadString( wTextStringID ) );
  61. lpText = (TCHAR FAR*)(const TCHAR *)sText;
  62. }
  63. CWnd *pcWnd = AfxGetMainWnd();
  64. if (pcWnd != NULL)
  65. {
  66. return pcWnd->MessageBox(lpText, lpCaption, nType | MB_TASKMODAL);
  67. }
  68. else
  69. {
  70. return ::MessageBox(NULL, lpText, lpCaption,nType | MB_TASKMODAL);
  71. }
  72. }
  73. int CmpMessageBoxString( CString& s,
  74. WORD wCaptionID,
  75. UINT nType )
  76. {
  77. TCHAR FAR* lpCaption;
  78. CString sText, sCaption;
  79. if( wCaptionID == CMPNOSTRING )
  80. lpCaption = NULL;
  81. else
  82. {
  83. VERIFY( sCaption.LoadString( wCaptionID ) );
  84. lpCaption = (TCHAR FAR*)(const TCHAR *)sCaption;
  85. }
  86. CWnd *pcWnd = AfxGetMainWnd();
  87. if (pcWnd != NULL)
  88. {
  89. return pcWnd->MessageBox((const TCHAR *)s, lpCaption,nType | MB_TASKMODAL);
  90. }
  91. else
  92. {
  93. return ::MessageBox(NULL, (const TCHAR *)s, lpCaption,nType | MB_TASKMODAL);
  94. }
  95. }
  96. int CmpMessageBox2( WORD wTextStringID,
  97. WORD wCaptionID,
  98. UINT nType,
  99. LPCTSTR szParam1,
  100. LPCTSTR szParam2 )
  101. {
  102. TCHAR FAR* lpText;
  103. TCHAR FAR* lpCaption;
  104. CString sText, sCaption;
  105. if( wCaptionID == CMPNOSTRING )
  106. lpCaption = NULL;
  107. else
  108. {
  109. VERIFY( sCaption.LoadString( wCaptionID ) );
  110. lpCaption = (TCHAR FAR*)(const TCHAR *)sCaption;
  111. }
  112. if( wTextStringID == CMPNOSTRING )
  113. lpText = TEXT("");
  114. else
  115. {
  116. AfxFormatString2( sText, wTextStringID, szParam1, szParam2);
  117. lpText = (TCHAR FAR*)(const TCHAR *)sText;
  118. }
  119. CWnd *pcWnd = AfxGetMainWnd();
  120. if (pcWnd != NULL)
  121. {
  122. return pcWnd->MessageBox(lpText, lpCaption, nType | MB_TASKMODAL);
  123. }
  124. else
  125. {
  126. return ::MessageBox(NULL, lpText, lpCaption,nType | MB_TASKMODAL);
  127. }
  128. }
  129. //
  130. // composer message box, combines wsprintf, you continue to
  131. // use string ids
  132. //
  133. // example:
  134. //
  135. // CmpMessageBoxPrintf( IDS_CANTOPEN, IDS_ERROR, MB_OK, lpszFileName );
  136. //
  137. #define nLocalBuf 512
  138. extern "C" int CDECL
  139. CmpMessageBoxPrintf(WORD wTextStringID, // string id of text (format)
  140. WORD wCaptionID, // string id of caption
  141. UINT nType, // same as message box
  142. ... ) // wsprintf arguments
  143. {
  144. TCHAR FAR* lpText;
  145. TCHAR FAR* lpCaption;
  146. CString sText, sCaption;
  147. int nBuf;
  148. TCHAR szBuffer[nLocalBuf];
  149. va_list args;
  150. va_start( args, nType );
  151. if( wCaptionID == CMPNOSTRING )
  152. lpCaption = NULL;
  153. else
  154. {
  155. VERIFY( sCaption.LoadString( wCaptionID ) );
  156. lpCaption = (TCHAR FAR*)(const TCHAR *)sCaption;
  157. }
  158. if( wTextStringID == CMPNOSTRING )
  159. lpText = TEXT("");
  160. else
  161. {
  162. VERIFY( sText.LoadString( wTextStringID ) );
  163. lpText = (TCHAR FAR*)(const TCHAR *)sText;
  164. }
  165. nBuf = wvsprintf( szBuffer, lpText, args );
  166. ASSERT( nBuf < nLocalBuf );
  167. CWnd *pcWnd = AfxGetMainWnd();
  168. if (pcWnd != NULL)
  169. {
  170. return pcWnd->MessageBox(szBuffer, lpCaption,nType | MB_TASKMODAL);
  171. }
  172. else
  173. {
  174. return ::MessageBox(NULL, szBuffer, lpCaption,nType | MB_TASKMODAL);
  175. }
  176. }