home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / dlgfr.cpp < prev    next >
C/C++ Source or Header  |  1998-06-16  |  4KB  |  133 lines

  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.  
  11. #include "stdafx.h"
  12. #include <stddef.h>     // for offsetof macro
  13.  
  14. #ifdef AFX_AUX_SEG
  15. #pragma code_seg(AFX_AUX_SEG)
  16. #endif
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. #define new DEBUG_NEW
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // Find/FindReplace dialogs
  27.  
  28. CFindReplaceDialog::CFindReplaceDialog() : CCommonDialog(NULL)
  29. {
  30.     memset(&m_fr, 0, sizeof(m_fr));
  31.     m_szFindWhat[0] = '\0';
  32.     m_szReplaceWith[0] = '\0';
  33.  
  34.     m_fr.Flags = FR_ENABLEHOOK;
  35.     if (!afxData.bWin4 && AfxHelpEnabled())
  36.         m_fr.Flags |= FR_SHOWHELP;
  37.     m_fr.lpfnHook = (COMMDLGPROC)_AfxCommDlgProc;
  38.     m_fr.lStructSize = sizeof(m_fr);
  39.     m_fr.lpstrFindWhat = (LPTSTR)m_szFindWhat;
  40. }
  41.  
  42. void CFindReplaceDialog::PostNcDestroy()
  43. {
  44.     ASSERT(m_hWnd == NULL);
  45.     delete this;
  46. }
  47.  
  48. BOOL CFindReplaceDialog::Create(BOOL bFindDialogOnly,
  49.     LPCTSTR lpszFindWhat, LPCTSTR lpszReplaceWith,
  50.     DWORD dwFlags, CWnd* pParentWnd)
  51. {
  52.     ASSERT_VALID(this);
  53.     ASSERT(m_fr.Flags & FR_ENABLEHOOK);
  54.     ASSERT(m_fr.lpfnHook != NULL);
  55.  
  56.     m_nIDHelp = bFindDialogOnly ? AFX_IDD_FIND : AFX_IDD_REPLACE;
  57.  
  58.     m_fr.wFindWhatLen = _countof(m_szFindWhat);
  59.     m_fr.lpstrReplaceWith = (LPTSTR)m_szReplaceWith;
  60.     m_fr.wReplaceWithLen = _countof(m_szReplaceWith);
  61.     m_fr.Flags |= dwFlags;
  62.  
  63.     if (pParentWnd == NULL)
  64.         m_fr.hwndOwner = AfxGetMainWnd()->GetSafeHwnd();
  65.     else
  66.     {
  67.         ASSERT_VALID(pParentWnd);
  68.         m_fr.hwndOwner = pParentWnd->m_hWnd;
  69.     }
  70.     ASSERT(m_fr.hwndOwner != NULL); // must have a parent for modeless dialog
  71.  
  72.     if (lpszFindWhat != NULL)
  73.         lstrcpyn(m_szFindWhat, lpszFindWhat, _countof(m_szFindWhat));
  74.  
  75.     if (lpszReplaceWith != NULL)
  76.         lstrcpyn(m_szReplaceWith, lpszReplaceWith, _countof(m_szReplaceWith));
  77.  
  78.     HWND hWnd;
  79.  
  80.     AfxHookWindowCreate(this);
  81.     if (bFindDialogOnly)
  82.         hWnd = ::FindText(&m_fr);
  83.     else
  84.         hWnd = ::ReplaceText(&m_fr);
  85.     if (!AfxUnhookWindowCreate())
  86.         PostNcDestroy();
  87.  
  88.     ASSERT(hWnd == NULL || hWnd == m_hWnd);
  89.     return hWnd != NULL;
  90. }
  91.  
  92. CFindReplaceDialog* PASCAL CFindReplaceDialog::GetNotifier(LPARAM lParam)
  93. {
  94.     ASSERT(lParam != NULL);
  95.     CFindReplaceDialog* pDlg;
  96.  
  97.     pDlg = (CFindReplaceDialog*)(lParam - offsetof(CFindReplaceDialog, m_fr));
  98.     ASSERT_VALID(pDlg);
  99.     ASSERT_KINDOF(CFindReplaceDialog, pDlg);
  100.  
  101.     return pDlg;
  102. }
  103.  
  104. ////////////////////////////////////////////////////////////////////////////
  105. // CFindReplaceDialog diagnostics
  106.  
  107. #ifdef _DEBUG
  108. void CFindReplaceDialog::Dump(CDumpContext& dc) const
  109. {
  110.     CDialog::Dump(dc);
  111.  
  112.     dc << "m_fr.hwndOwner = " << (UINT)m_fr.hwndOwner;
  113.     dc << "\nm_fr.Flags = " << (LPVOID)m_fr.Flags;
  114.     dc << "\nm_fr.lpstrFindWhat = " << m_fr.lpstrFindWhat;
  115.     dc << "\nm_fr.lpstrReplaceWith = " << m_fr.lpstrReplaceWith;
  116.  
  117.     if (m_fr.lpfnHook == (COMMDLGPROC)_AfxCommDlgProc)
  118.         dc << "\nhook function set to standard MFC hook function";
  119.     else
  120.         dc << "\nhook function set to non-standard hook function";
  121.  
  122.     dc << "\n";
  123. }
  124. #endif //_DEBUG
  125.  
  126. #ifdef AFX_INIT_SEG
  127. #pragma code_seg(AFX_INIT_SEG)
  128. #endif
  129.  
  130. IMPLEMENT_DYNAMIC(CFindReplaceDialog, CDialog)
  131.  
  132. ////////////////////////////////////////////////////////////////////////////
  133.