dlgfr.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #include "stdafx.h"
  11. #include <stddef.h> // for offsetof macro
  12. #ifdef AFX_AUX_SEG
  13. #pragma code_seg(AFX_AUX_SEG)
  14. #endif
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. #define new DEBUG_NEW
  20. /////////////////////////////////////////////////////////////////////////////
  21. // Find/FindReplace dialogs
  22. CFindReplaceDialog::CFindReplaceDialog() : CCommonDialog(NULL)
  23. {
  24. memset(&m_fr, 0, sizeof(m_fr));
  25. m_szFindWhat[0] = '\0';
  26. m_szReplaceWith[0] = '\0';
  27. m_fr.Flags = FR_ENABLEHOOK;
  28. if (!afxData.bWin4 && AfxHelpEnabled())
  29. m_fr.Flags |= FR_SHOWHELP;
  30. m_fr.lpfnHook = (COMMDLGPROC)_AfxCommDlgProc;
  31. m_fr.lStructSize = sizeof(m_fr);
  32. m_fr.lpstrFindWhat = (LPTSTR)m_szFindWhat;
  33. }
  34. void CFindReplaceDialog::PostNcDestroy()
  35. {
  36. ASSERT(m_hWnd == NULL);
  37. delete this;
  38. }
  39. BOOL CFindReplaceDialog::Create(BOOL bFindDialogOnly,
  40. LPCTSTR lpszFindWhat, LPCTSTR lpszReplaceWith,
  41. DWORD dwFlags, CWnd* pParentWnd)
  42. {
  43. ASSERT_VALID(this);
  44. ASSERT(m_fr.Flags & FR_ENABLEHOOK);
  45. ASSERT(m_fr.lpfnHook != NULL);
  46. m_nIDHelp = bFindDialogOnly ? AFX_IDD_FIND : AFX_IDD_REPLACE;
  47. m_fr.wFindWhatLen = _countof(m_szFindWhat);
  48. m_fr.lpstrReplaceWith = (LPTSTR)m_szReplaceWith;
  49. m_fr.wReplaceWithLen = _countof(m_szReplaceWith);
  50. m_fr.Flags |= dwFlags;
  51. if (pParentWnd == NULL)
  52. m_fr.hwndOwner = AfxGetMainWnd()->GetSafeHwnd();
  53. else
  54. {
  55. ASSERT_VALID(pParentWnd);
  56. m_fr.hwndOwner = pParentWnd->m_hWnd;
  57. }
  58. ASSERT(m_fr.hwndOwner != NULL); // must have a parent for modeless dialog
  59. if (lpszFindWhat != NULL)
  60. lstrcpyn(m_szFindWhat, lpszFindWhat, _countof(m_szFindWhat));
  61. if (lpszReplaceWith != NULL)
  62. lstrcpyn(m_szReplaceWith, lpszReplaceWith, _countof(m_szReplaceWith));
  63. HWND hWnd;
  64. AfxHookWindowCreate(this);
  65. if (bFindDialogOnly)
  66. hWnd = ::FindText(&m_fr);
  67. else
  68. hWnd = ::ReplaceText(&m_fr);
  69. if (!AfxUnhookWindowCreate())
  70. PostNcDestroy();
  71. ASSERT(hWnd == NULL || hWnd == m_hWnd);
  72. return hWnd != NULL;
  73. }
  74. CFindReplaceDialog* PASCAL CFindReplaceDialog::GetNotifier(LPARAM lParam)
  75. {
  76. ASSERT(lParam != NULL);
  77. CFindReplaceDialog* pDlg;
  78. pDlg = (CFindReplaceDialog*)(lParam - offsetof(CFindReplaceDialog, m_fr));
  79. ASSERT_VALID(pDlg);
  80. ASSERT_KINDOF(CFindReplaceDialog, pDlg);
  81. return pDlg;
  82. }
  83. ////////////////////////////////////////////////////////////////////////////
  84. // CFindReplaceDialog diagnostics
  85. #ifdef _DEBUG
  86. void CFindReplaceDialog::Dump(CDumpContext& dc) const
  87. {
  88. CDialog::Dump(dc);
  89. dc << "m_fr.hwndOwner = " << (UINT)m_fr.hwndOwner;
  90. dc << "\nm_fr.Flags = " << (LPVOID)m_fr.Flags;
  91. dc << "\nm_fr.lpstrFindWhat = " << m_fr.lpstrFindWhat;
  92. dc << "\nm_fr.lpstrReplaceWith = " << m_fr.lpstrReplaceWith;
  93. if (m_fr.lpfnHook == (COMMDLGPROC)_AfxCommDlgProc)
  94. dc << "\nhook function set to standard MFC hook function";
  95. else
  96. dc << "\nhook function set to non-standard hook function";
  97. dc << "\n";
  98. }
  99. #endif //_DEBUG
  100. #ifdef AFX_INIT_SEG
  101. #pragma code_seg(AFX_INIT_SEG)
  102. #endif
  103. IMPLEMENT_DYNAMIC(CFindReplaceDialog, CDialog)
  104. ////////////////////////////////////////////////////////////////////////////