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.

187 lines
4.0 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1998 - 1998
  3. All rights reserved.
  4. Module Name:
  5. msgbox.cxx
  6. Abstract:
  7. MessageBox class
  8. Author:
  9. Steve Kiraly (SteveKi) 03/23/98
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. #include "msgbox.hxx"
  15. /*++
  16. Routine Name:
  17. PrintUIMessageBox
  18. Routine Description:
  19. This routine is very similar to the win32 MessageBox except it
  20. creates a hidden dialog when the user request that a help button
  21. be displayed. The MessageBox api is some what broken
  22. with respect to the way the help button works. When the help button is
  23. clicked the MessageBox api will send a help event to the parent window.
  24. It is the responsiblity of the parent window to respond corectly, i.e.
  25. start either WinHelp or HtmlHelp. Unfortunatly not in all cases does the
  26. caller have a parent window or has ownership to the parent window code to
  27. add suport for the help event. In these case is why someone would use this
  28. function.
  29. Arguments:
  30. hWnd - handle of owner window
  31. lpText - address of text in message box
  32. lpCaption - address of title of message box
  33. uType - style of message box
  34. pfHelpCallback - pointer to function called when a WM_HELP message is received, this
  35. parameter is can be NULL then api acts like MessageBox.
  36. pRefData - user defined refrence data passed along to the callback routine,
  37. this paremeter can be NULL.
  38. Return Value:
  39. See windows sdk for return values from MessageBox
  40. --*/
  41. INT
  42. PrintUIMessageBox(
  43. IN HWND hWnd,
  44. IN LPCTSTR pszMsg,
  45. IN LPCTSTR pszTitle,
  46. IN UINT uFlags,
  47. IN pfHelpCallback pCallback, OPTIONAL
  48. IN PVOID pRefData OPTIONAL
  49. )
  50. {
  51. SPLASSERT( pszMsg );
  52. SPLASSERT( pszTitle );
  53. INT iRetval = 0;
  54. //
  55. // If the caller specifed the help flag and provided a callback then
  56. // use the message box dialog class to display the message box, otherwise
  57. // fall back to the original behavior of MessageBox.
  58. //
  59. if( ( uFlags & MB_HELP ) && pCallback )
  60. {
  61. TMessageBoxDialog Dialog( hWnd, uFlags, pszTitle, pszMsg, pCallback, pRefData );
  62. if( VALID_OBJ( Dialog ) )
  63. {
  64. iRetval = Dialog.iMessageBox();
  65. }
  66. }
  67. else
  68. {
  69. //
  70. // Display the message box.
  71. //
  72. iRetval = ::MessageBox( hWnd, pszMsg, pszTitle, uFlags );
  73. }
  74. return iRetval;
  75. }
  76. /********************************************************************
  77. Message box helper class.
  78. ********************************************************************/
  79. TMessageBoxDialog::
  80. TMessageBoxDialog(
  81. IN HWND hWnd,
  82. IN UINT uFlags,
  83. IN LPCTSTR pszTitle,
  84. IN LPCTSTR pszMsg,
  85. IN pfHelpCallback pCallback,
  86. IN PVOID pRefData
  87. ) : _hWnd( hWnd ),
  88. _uFlags( uFlags ),
  89. _pszTitle( pszTitle ),
  90. _pszMsg( pszMsg ),
  91. _pCallback( pCallback ),
  92. _pRefData( pRefData ),
  93. _iRetval( 0 )
  94. {
  95. }
  96. TMessageBoxDialog::
  97. ~TMessageBoxDialog(
  98. VOID
  99. )
  100. {
  101. }
  102. BOOL
  103. TMessageBoxDialog::
  104. bValid(
  105. VOID
  106. ) const
  107. {
  108. return TRUE;
  109. }
  110. INT
  111. TMessageBoxDialog::
  112. iMessageBox(
  113. VOID
  114. )
  115. {
  116. _iRetval = 0;
  117. DialogBoxParam( ghInst,
  118. MAKEINTRESOURCE( DLG_MESSAGE_BOX ),
  119. _hWnd,
  120. MGenericDialog::SetupDlgProc,
  121. (LPARAM)this );
  122. return _iRetval;
  123. }
  124. BOOL
  125. TMessageBoxDialog::
  126. bHandleMessage(
  127. IN UINT uMsg,
  128. IN WPARAM wParam,
  129. IN LPARAM lParam
  130. )
  131. {
  132. BOOL bStatus = TRUE;
  133. switch (uMsg)
  134. {
  135. case WM_INITDIALOG:
  136. ShowWindow( _hDlg, SW_HIDE );
  137. _iRetval = ::MessageBox( _hDlg, _pszMsg, _pszTitle, _uFlags );
  138. EndDialog( _hDlg, IDOK );
  139. break;
  140. case WM_HELP:
  141. bStatus = ( _pCallback ) ? _pCallback( _hDlg, _pRefData ) : FALSE;
  142. break;
  143. default:
  144. bStatus = FALSE;
  145. break;
  146. }
  147. return bStatus;
  148. }