home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / MFC / SRC / DLGFR.CP_ / DLGFR.CP
Encoding:
Text File  |  1993-02-08  |  3.8 KB  |  148 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library. 
  2. // Copyright (C) 1992 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 Microsoft 
  7. // QuickHelp and/or WinHelp documentation provided with the library. 
  8. // See these sources for detailed information regarding the 
  9. // Microsoft Foundation Classes product. 
  10.  
  11.  
  12. #include "stdafx.h"
  13. #include <stddef.h>     // for offsetof macro
  14.  
  15. #ifdef AFX_AUX_SEG
  16. #pragma code_seg(AFX_AUX_SEG)
  17. #endif
  18.  
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char BASED_CODE THIS_FILE[] = __FILE__;
  22. #define new DEBUG_NEW
  23. #endif
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // Find/FindReplace dialogs
  27.  
  28. IMPLEMENT_DYNAMIC(CFindReplaceDialog, CDialog)
  29.  
  30. CFindReplaceDialog::CFindReplaceDialog()
  31. {
  32.     memset(&m_fr, 0, sizeof(m_fr));
  33.     m_szFindWhat[0] = '\0';
  34.     m_szReplaceWith[0] = '\0';
  35.  
  36.     m_fr.Flags = FR_ENABLEHOOK;
  37.     if (_AfxHelpEnabled())
  38.         m_fr.Flags |= FR_SHOWHELP;
  39.     m_fr.lpfnHook = (COMMDLGPROC)_AfxCommDlgProc;
  40.     m_fr.lStructSize = sizeof(m_fr);
  41.     m_fr.lpstrFindWhat = (LPSTR)m_szFindWhat;
  42. }
  43.  
  44. void CFindReplaceDialog::PostNcDestroy()
  45. {
  46.     ASSERT(m_hWnd == NULL);
  47.     delete this;
  48. }
  49.  
  50.  
  51. BOOL CFindReplaceDialog::Create(BOOL bFindDialogOnly,
  52.         LPCSTR lpszFindWhat,
  53.         LPCSTR lpszReplaceWith /* = NULL */,
  54.         DWORD dwFlags /* = FR_DOWN */,
  55.         CWnd* pParentWnd /* = NULL */)
  56. {
  57.     ASSERT_VALID(this);
  58.     ASSERT(m_fr.Flags & FR_ENABLEHOOK);
  59.     ASSERT(m_fr.lpfnHook != NULL);
  60.  
  61.     HWND hWnd;
  62.  
  63.     m_nIDHelp = lpszReplaceWith ? AFX_IDD_REPLACE : AFX_IDD_FIND;
  64.  
  65.     m_fr.wFindWhatLen = sizeof(m_szFindWhat);
  66.     m_fr.lpstrReplaceWith = (LPSTR)m_szReplaceWith;
  67.     m_fr.wReplaceWithLen = sizeof(m_szReplaceWith);
  68.     m_fr.Flags |= dwFlags;
  69.  
  70.     if (pParentWnd == NULL)
  71.         m_fr.hwndOwner = AfxGetApp()->m_pMainWnd->GetSafeHwnd();
  72.     else
  73.     {
  74.         ASSERT_VALID(pParentWnd);
  75.         m_fr.hwndOwner = pParentWnd->m_hWnd;
  76.     }
  77.     ASSERT(m_fr.hwndOwner != NULL); // must have a parent for modeless dialog
  78.     
  79.  
  80.     if (lpszFindWhat)
  81.         _AfxStrCpy(m_szFindWhat, lpszFindWhat, sizeof(m_szFindWhat));
  82.  
  83.     if (lpszReplaceWith)
  84.         _AfxStrCpy(m_szReplaceWith, lpszReplaceWith, sizeof(m_szReplaceWith));
  85.  
  86.     _AfxHookWindowCreate(this);
  87.     if (bFindDialogOnly)
  88.         hWnd = ::FindText(&m_fr);
  89.     else
  90.         hWnd = ::ReplaceText(&m_fr);
  91.     if (!_AfxUnhookWindowCreate())
  92.         PostNcDestroy();
  93.  
  94.     if (hWnd == NULL)
  95.         return FALSE;
  96.     ASSERT(hWnd == m_hWnd);
  97.     return TRUE;
  98. }
  99.  
  100. void CFindReplaceDialog::OnOK()
  101. {
  102.     // Common dialogs do not require ::EndDialog
  103.     ASSERT_VALID(this);
  104.     Default();
  105. }
  106.  
  107. void CFindReplaceDialog::OnCancel()
  108. {
  109.     // Common dialogs do not require ::EndDialog
  110.     ASSERT_VALID(this);
  111.     Default();
  112. }
  113.  
  114. CFindReplaceDialog* PASCAL CFindReplaceDialog::GetNotifier(LPARAM lParam)
  115. {
  116.     ASSERT(lParam != NULL);
  117.     CFindReplaceDialog* pDlg;
  118.  
  119.     pDlg = (CFindReplaceDialog*)(lParam - offsetof(CFindReplaceDialog, m_fr));
  120.     ASSERT_VALID(pDlg);
  121.     ASSERT(pDlg->IsKindOf(RUNTIME_CLASS(CFindReplaceDialog)));
  122.     
  123.     return pDlg;
  124. }
  125.  
  126. ////////////////////////////////////////////////////////////////////////////
  127. // CFindReplaceDialog diagnostics
  128.  
  129. #ifdef _DEBUG
  130. void CFindReplaceDialog::Dump(CDumpContext& dc) const
  131. {
  132.     ASSERT_VALID(this);
  133.  
  134.     CDialog::Dump(dc);
  135.  
  136.     AFX_DUMP1(dc, "\nm_fr.hwndOwner = ", (UINT)m_fr.hwndOwner);
  137.     AFX_DUMP1(dc, "\nm_fr.Flags = ", (LPVOID)m_fr.Flags);
  138.     AFX_DUMP1(dc, "\nm_fr.lpstrFindWhat = ", m_fr.lpstrFindWhat);
  139.     AFX_DUMP1(dc, "\nm_fr.lpstrReplaceWith = ", m_fr.lpstrReplaceWith);
  140.     if (m_fr.lpfnHook == (COMMDLGPROC)_AfxCommDlgProc)
  141.         AFX_DUMP0(dc, "\nhook function set to standard MFC hook function");
  142.     else
  143.         AFX_DUMP0(dc, "\nhook function set to non-standard hook function");
  144. }
  145. #endif //_DEBUG
  146.  
  147. ////////////////////////////////////////////////////////////////////////////
  148.