刚才看了个贴子:
想要将CFindReplaceDialog类作为基类。类似CFileDialog   CColorDialog   CFontDialog  。
因为他们都是通用对话框。但是,我查到的结果是------好像除了CFindReplaceDialog类,其他
几个CFileDialog   CColorDialog   CFontDialog  是可以做基类的。我刚才研究了一下,并没有太大进展,所以发个贴子,
大家讨论一下。我刚才想用的方法是:
现以CDialog为基类,建立这个CMyFindDlg的新类。然后将里面的CDialog的地方换成CFindReplaceDialog。并作了很多其它修改:
如----
    DECLARE_DYNAMIC(CMyFindDlg) //新加的,
// Construction
public:         //CMyFindDlg的构造,参照CFindReplaceDialog的Create参数。
    CMyFindDlg( BOOL bFindDialogOnly,
             LPCTSTR lpszFindWhat,
             LPCTSTR lpszReplaceWith = NULL,
             DWORD dwFlags = FR_DOWN, 
             CWnd* pParentWnd = NULL );
并将void CMyFindDlg::DoDataExchange(CDataExchange* pDX)删除。最终做到和声明一个以CFileDialog通用对话框为基类的CMyFileDlg一样的格式。运行后看看这个CMyFindDlg定义的是否有问题。
编译通过。
--------------------
下面就是要看能不能用CMyFindDlg定义对象了。接下来,在void CMainFrame::OnFind() 
{
// TODO: Add your command handler code here
CMyFindDlg dlg;
}想参生一个CMyFindDlg 的对象,可是失败了提示:: error C2512: 'CMyFindDlg' : no appropriate default constructor available看来还是我的CMyFindDlg 类不成功。大家有什么好办法???

解决方案 »

  1.   

    构造函数需要的参数是在实例化一个类的时候传进去的。所以在声明一个类的对象时,如果它没有默认构造函数,你应该在变量名后边加上构造函数所需的参数:
      CMyFindDlg dlg(a,b,......);
      

  2.   

    我看我另外类似的用CMyFileDlg做基类的新类---CMyFlieDlg里
    好像并不要什么构造函数。
    那个是不是可能是继承了CFileDialog里的构造函数。而到了用CFindReplaceDialog做基类,
    它的构造函数我不太清楚,只在MSDN里查到了它的Create函数的参数。所以你看上面我才有:
    public:         //CMyFindDlg的构造,参照CFindReplaceDialog的Create参数。
        CMyFindDlg( BOOL bFindDialogOnly,
                 LPCTSTR lpszFindWhat,
                 LPCTSTR lpszReplaceWith = NULL,
                 DWORD dwFlags = FR_DOWN, 
                 CWnd* pParentWnd = NULL );
    。。
      

  3.   

    CFindReplaceDialog做基类,
    就是想继承他的构造函数。就像CcolorDialog做基类派生的新类CMycolorDlg后只要CMycolorDlg dlg就行了。我也就是想要这样。
    你说的CMyFindDlg dlg(a,b,......);
    加参数,我恐怕自己做不来呀。
      

  4.   

    对不起。错了。
    上面的CMycolorDlg dlg似乎不行,看来必须有参数才行。那么要怎么写呀?
      

  5.   

    由于CFindReplaceDialog是一个modeless dialogs无模式通用对话框!
    所以不能用DoModal()
    我能不能这样:
    以CFindReplaceDialog为基类。
    重载CFindReplaceDialog的Create函数?这个应该怎么做:
    我试了一下,没成功。
    ---------------
    CMyFindDlg.h中: //原来定义是错误的。
    BOOL Create(BOOL bFindDialogOnly, 
    LPCTSTR lpszFindWhat,
    LPCTSTR lpszReplaceWith = NULL,
    DWORD dwFlags = FR_DOWN,
    CWnd* pParentWnd = NULL);
    //现在希望的是重载CFindReplaceDialog的Create函数,所以在
    CMyFindDlg.h中声明BOOL Create()在CMyFindDlg.cpp中
    应该怎么样写才是调用的是基类CFindReplaceDialog的Create函数?
    我写的是:
    CMyFindDlg::Create(BOOL bFindDialogOnly, LPCTSTR lpszFindWhat,
         LPCTSTR lpszReplaceWith, DWORD dwFlags, CWnd* pParentWnd )
    {
     return TRUE;
    }
    但测试发现错误,调用的是派生类的CMyFindDlg::Create()如果写成:
    CMyFindDlg::Create(BOOL bFindDialogOnly, LPCTSTR lpszFindWhat,
         LPCTSTR lpszReplaceWith, DWORD dwFlags, CWnd* pParentWnd )
       :CFindReplaceDialog::Create(bFindDialogOnly, lpszFindWhat,
                 lpszReplaceWith, dwFlags,  pParentWnd)
    {
     return TRUE;
    }
    有无法编译通过:
    显示错误:
    : error C2550: 'Create' : constructor initializer lists are only allowed on constructor definitions。该怎么办???
      

  6.   

    CMyFindDlg::Create(BOOL bFindDialogOnly, LPCTSTR lpszFindWhat,
         LPCTSTR lpszReplaceWith, DWORD dwFlags, CWnd* pParentWnd )
    {
     return CFindReplaceDialog::Create(bFindDialogOnly, lpszFindWhat,
                 lpszReplaceWith, dwFlags,  pParentWnd);
    }
      

  7.   

    这样可以吗?我还以为只能:
    CMyFindDlg::Create(BOOL bFindDialogOnly, LPCTSTR lpszFindWhat,
         LPCTSTR lpszReplaceWith, DWORD dwFlags, CWnd* pParentWnd )
       :CFindReplaceDialog::Create(bFindDialogOnly, lpszFindWhat,
                 lpszReplaceWith, dwFlags,  pParentWnd);
    {
    }
    呢!
      

  8.   

    我用CFindReplaceDialog类 创建一个 通用的查找对话框!对话框是出现了!不过要实现真正的查找,还要做些什么?这方面好像没有那本书上讲过具体的。所以才向大家请教。
      

  9.   

    这样:
    m_pMyFindDialog= new CFindReplaceDialog();
    m_pMyFindDialog->Create(TRUE,NULL,NULL,FR_DOWN,this);
    m_pMyFindDialog->SetActiveWindow();
    m_pMyFindDialog->ShowWindow(TRUE);
    可以出来呀!
      

  10.   

    你说自己写代码----替换,
    那对于查找,一样吧!也要写个什么,调用
    FindNext 
    GetNotifier 
    GetFindString 
    GetReplaceString 
    IsTerminating 
    MatchCase 
    MatchWholeWord  
    ReplaceAll 
    ReplaceCurrent 
    SearchDown 
    这个类对象的函数????看人家,在函数
    LRESULT CMainFrame::OnFindDialogMessage(WPARAM wParam, LPARAM lParam)
    里,调用都成功了,我的怎么不行呢?
      

  11.   

    这么个贴子,怎么没人看到:没人能解答我吗?连同:
    http://expert.csdn.net/Expert/topic/1235/1235207.xml?temp=.901211
    http://expert.csdn.net/Expert/topic/1235/1235211.xml?temp=.8234522
      

  12.   

    CFindReplaceDialog dlg;
    dlg.Create(TRUE,"");-----------------------------------------------------------------
    Creates and displays either a Find or Find/Replace dialog box object, depending on the value of bFindDialogOnly.In order for the parent window to be notified of find/replace requests, you must use the WindowsRegisterWindowMessage function whose return value is a message number unique to the application’s instance. Your frame window should have a message map entry that declares the callback function (OnFindReplace in the example that follows) that handles this registered message. The following code fragment is an example of how to do this for a frame window class named CMyFrameWnd:    class CMyFrameWnd : public CFrameWnd
        {
        protected:
            afx_msg LONG OnFindReplace(WPARAM wParam, LPARAM lParam);        DECLARE_MESSAGE_MAP()
        };
        static UINT WM_FINDREPLACE = ::RegisterWindowMessage(FINDMSGSTRING);    BEGIN_MESSAGE_MAP( CMyFrameWnd, CFrameWnd )
           //Normal message map entries here.
           ON_REGISTERED_MESSAGE( WM_FINDREPLACE, OnFindReplace )
        END_MESSAGE_MAPWithin your OnFindReplace function, you interpret the intentions of the user and create the code for the find/replace operations.
    注意最后两行的说明,你应该写一个消息函数来处理真正的查找/替换工作。
      

  13.   

    这样来实现具体的“查找/替换”功能:在你使用CFindReplaceDialog的类中,在类定义中增加消息函数声明:
    afx_msg LONG OnFindReplace(WPARAM wParam, LPARAM lParam);在类定义外(.h文件中)加入:
    static UINT WM_FINDREPLACE = ::RegisterWindowMessage(FINDMSGSTRING);在类的实现文件中,消息映射处增加代码:
    BEGIN_MESSAGE_MAP( CMyFrameWnd, CFrameWnd )
           //Normal message map entries here.
           ON_REGISTERED_MESSAGE( WM_FINDREPLACE, OnFindReplace )  //加入该行
    END_MESSAGE_MAP在类的实现文件中,加入消息响应函数的实现代码,如:
    LONG CYourClass::OnFindReplace(WPARAM wParam, LPARAM lParam)
    {
       //实现查找功能的代码
       MessageBox("you see, it can work now!");   //测试用
    }不知说明白没有,我试过了,可以的。
    根据是上一贴英文的资料所述内容。
      

  14.   

    我没具体实现“查找功能的代码”,我只是觉得应该写在这里。
    而且这个查找功能应该有一定的查找对象啊,比如如果你使用的是CEditView或CRichEditView,他就是在编辑器的buffer中查找,但是你用的是CView吧?那你是在什么中查找呢?我可能没看全你的内容,所述不知重复与否。
      

  15.   

    我也知道写在这个!:我的View视图类的基类用的是CEditView!如果用的是CRichEditView,那就不用那么麻烦了:CRichEditView创建的SDI里本身就有查找功能,
    而且如果是CRichEditView做基类,那就可以用函数AdjustDialogPosition()了。
    该写查找代码的地方用
    if(FindText(pFindReplace->GetFindString(),FALSE,FALSE))
    AdjustDialogPosition(pFindReplace);  
    就可以了!
    ------------因为有个例子就是这样的。
    但现在视图类的基类是CEditView,我就不知道怎么写了。光用FindText(pFindReplace->GetFindString(),FALSE,FALSE),
    效果出来就是:
    比如,我输入了3行s
    ssssssssssssss
    ssssssssssssssss *
    ssssssssssssss
    把鼠标放到*的地方,查找ss,
    那么就是从*的前面一个ss开始,一直往前,
    不断的点查找下一个,就一直往前,
    到了最前面就停住了。不能循环!!!
    ---------------------------------------
    你说呢!
      

  16.   

    可以作为基类!只是一般没有意义,除非你要改变默认的cfindreplacedialog对话框!
    ------------------------------
    我已经解决了这个问题!TNND,我第一次时,竟然将消息处理代码写在CMainFrame 中去了,搞得我得不到自己注册的消息!
    ---------一度怀疑自己的能力,想不到竟然翻了个如此低级的错误!
    实践是检验真理的唯一标准!
    [email protected]
    ------------------------------------------------
    class CUseReplaceDialogView : public CEditView
    {
    protected: // create from serialization only
    CUseReplaceDialogView();
    DECLARE_DYNCREATE(CUseReplaceDialogView)// Attributes
    public:
    CUseReplaceDialogDoc* GetDocument();
    BOOL FindText( LPCTSTR lpszFind, BOOL bNext = TRUE, BOOL bCase = TRUE );
    CFindReplaceDialog  *m_pFRDlg;
     bool bFirstSearchTime;

    // Operations
    public:// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CUseReplaceDialogView)
    public:
    virtual void OnDraw(CDC* pDC);  // overridden to draw this view
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
    protected:
    //}}AFX_VIRTUAL// Implementation
    public:
    virtual ~CUseReplaceDialogView();
    #ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
    #endifprotected:// Generated message map functions
    protected:
    //{{AFX_MSG(CUseReplaceDialogView)
    afx_msg void OnFind();
    //}}AFX_MSG
    afx_msg LRESULT OnFindReplace(WPARAM wParam,LPARAM lParam);
    DECLARE_MESSAGE_MAP()
    };#ifndef _DEBUG  // debug version in UseReplaceDialogView.cpp
    inline CUseReplaceDialogDoc* CUseReplaceDialogView::GetDocument()
       { return (CUseReplaceDialogDoc*)m_pDocument; }
    #endif///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_USEREPLACEDIALOGVIEW_H__B3EC2E7A_1258_4579_BC73_4A27411D28DE__INCLUDED_)---------------------------------------------------------------------------------------------
    static UINT FindReplaceDialogMessage = 
     ::RegisterWindowMessage(FINDMSGSTRING);/////////////////////////////////////////////////////////////////////////////
    // CUseReplaceDialogViewIMPLEMENT_DYNCREATE(CUseReplaceDialogView, CEditView)BEGIN_MESSAGE_MAP(CUseReplaceDialogView, CEditView)
    //{{AFX_MSG_MAP(CUseReplaceDialogView)
    ON_COMMAND(ID_SEARCH_REPLACE, OnFind)
    //}}AFX_MSG_MAP
    ON_REGISTERED_MESSAGE(FindReplaceDialogMessage, OnFindReplace )
    END_MESSAGE_MAP()CUseReplaceDialogView::CUseReplaceDialogView()
    {
    // TODO: add construction code here
    m_pFRDlg=NULL;
    bFirstSearchTime=true;
    }
    BOOL CUseReplaceDialogView:: FindText( LPCTSTR lpszFind, BOOL bNext ,BOOL bCase )
    {
    if(bFirstSearchTime)
    {
    CString str;
    CEdit &editCtrl=this->GetEditCtrl();
    editCtrl.SetSel(0,0);//将搜寻起点设置在cedit 得开始部分
    this->bFirstSearchTime=false;
    }
    return CEditView::FindText(lpszFind,
                  bNext,
                  bCase);
    }
    void CUseReplaceDialogView::OnFind() 
    {
    // TODO: Add your command handler code here
    if(m_pFRDlg==NULL)
    {
          m_pFRDlg = new CFindReplaceDialog();  // Must be created on the heap
      m_pFRDlg->m_fr.lStructSize = sizeof(FINDREPLACE);
          m_pFRDlg->m_fr.hwndOwner = this->m_hWnd;      m_pFRDlg->Create( false, "", "", FR_DOWN | FR_WHOLEWORD, this ); 
          }

    }
    LRESULT CUseReplaceDialogView::OnFindReplace(WPARAM  wParam,LPARAM lParam) 
    {
    // TODO: Add your command handler code here
     CFindReplaceDialog* pFindReplace = 
      CFindReplaceDialog::GetNotifier(lParam); ASSERT(pFindReplace != NULL); if (pFindReplace->IsTerminating())
     {
      m_pFRDlg = NULL;
      this->bFirstSearchTime=true;
     }
     else if (pFindReplace->FindNext())
     {
      if(FindText(pFindReplace->GetFindString(),
                  true,
                  FALSE))
      ;
       //AdjustDialogPosition(pFindReplace);
      else
      {
      this->bFirstSearchTime=true;
      OnTextNotFound(pFindReplace->GetFindString());
      MessageBox("Have reached the end of line,Cannt find!");
      }
     }
    return 0;
    }
      

  17.   

    此问题完成的差不多了。
    这个先结了,剩下的问题都到:http://expert.csdn.net/Expert/topic/1235/1235211.xml?temp=2.567691E-02里解决。谢谢大家。