源贴:http://expert.csdn.net/Expert/topic/1227/1227683.xml?temp=.1629602现在在:
菜单点击后,正常的查找对话框弹出,说明,其创建已经完成。主要是那个void CMainFrame::OnFind() 函数。现在有了查找对话框,但是点击后没有效果。察看其他文章,还有很多代码没有。所以:
加入:
static UINT FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);
//加入上面那句。
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_FINDDLG, OnFind)
//}}AFX_MSG_MAP
    ON_REGISTERED_MESSAGE(FindDialogMessage, OnFindDialogMessage) 加入这个。
END_MESSAGE_MAP()还有函数OnFindDialogMessage()
LRESULT CMainFrame::OnFindDialogMessage(WPARAM wParam, LPARAM lParam)
{
   CFindReplaceDialog *pDlg = CFindReplaceDialog::GetNotifier(lParam);   if( NULL != pDlg )
   {
      // Use pDlg as a pointer to the existing FindReplace dlg to 
      // call CFindReplaceDialog member functions
      是不是要在此处 加入相应的代码,才可以实现真正的查找功能??
      //我只加入下面2句,没作用呀!!!
      pDlg->GetFindString();
  pDlg->FindNext();   }
return 0;
}--------------
现在就是怎么让弹出的通用查找对话框 实现真正的查找功能!2个贴子是差不多,先谢了。

解决方案 »

  1.   

    今天是怎么搞的,贴的东西都不全!!急人!-------------------------------------------------
    void CMainFrame::OnFind()函数已经完成了
    创建通用查找对话框,但是还是不能实现真正的查找功能,点击查找后没有效果。看了些相关的东西发现,还有很多东西没有写。
    所以,又加入:static UINT FindDialogMessage = ::RegisterWindowMessageFINDMSGSTRING); //新加的BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
    //{{AFX_MSG_MAP(CMainFrame)
    ON_WM_CREATE()
    ON_COMMAND(ID_FINDDLG, OnFind)
    //}}AFX_MSG_MAP
        ON_REGISTERED_MESSAGE(FindDialogMessage, OnFindDialogMessage)
        //上面一行是 新加的
    END_MESSAGE_MAP()
    又加入了函数OnFindDialogMessage()
    LRESULT CMainFrame::OnFindDialogMessage(WPARAM wParam, LPARAM lParam)
    {
       CFindReplaceDialog *pDlg = CFindReplaceDialog::GetNotifier(lParam);   if( NULL != pDlg )
       {
          // Use pDlg as a pointer to the existing FindReplace dlg to 
          // call CFindReplaceDialog member functions
          //好像应该在这个地方加入代码,才能实现真正的查找功能,
          //但是加入什么??不解!我加的下面2句没有效果!!
          pDlg->GetFindString();
          pDlg->FindNext();   }
    return 0;
    }
    ---------------------------
    现在的问题就是创建后怎么实现真正的查找功能!
    2个贴子是一样的。
      

  2.   

    此贴为主贴:还有两个相关的:
    http://expert.csdn.net/Expert/topic/1227/1227683.xml?temp=.2166254
    http://expert.csdn.net/Expert/topic/1235/1235211.xml?temp=.769787一共300分,都没人肯帮吗?看来真是难道大家和我一样?
    -----------
    网上招来找去,都只是说的通用对话框中 包含这样 一种 查找/替代的对话框。
    具体的旧没什么内容了,书上的就更少了。
    去国外的吧,看了看,也很少,而且要研究清除也不容易。
    所以想找,看看谁有这样的经验。
    -------------------------------
    之所以这么少的内容,我想主要原因还是这个 通用对话框的特殊---
    他是个无模式,直接不能选择做基类(但自己可以添加)。
    -------------------------------
    把这个问题搞清楚,我想不仅对我,对其他人也有好处,所以心中很是希望能将这个问题解决。期待中。
      

  3.   

    看了另外的类似代码:
    一个由于view的基类是CRichEditView,
    可以在函数OnFindReplaceMessage(WPARAM wParam, LPARAM lParam)里使用
    if (pFindReplace->FindNext())
    {
    if(FindText(pFindReplace->GetFindString(),FALSE,FALSE))
    AdjustDialogPosition(pFindReplace);   else
    TextNotFound(pFindReplace->GetFindString());
            }
    因为AdjustDialogPosition(pFindReplace); 需要基类为CRichEditView。可我的视图的基类不是的话那要怎么写?
    --------------------------------
    另外:codeproject上的一个文章里也有这样的介绍,不过就能奇怪了:
    他用:
        if(m_pFindDialog->FindNext())
        {
            //read data from dialog
            CString FindName = m_pFindDialog->GetFindString();
            bool bMatchCase = m_pFindDialog->MatchCase() == TRUE;
            bool bMatchWholeWord = m_pFindDialog->MatchWholeWord() == TRUE;
            bool bSearchDown = m_pFindDialog->SearchDown() == TRUE;        //with given name do search
            FindWhatYouNeed(FindName, bMatchCase, bMatchWholeWord, bSearchDown);
        }
    里面的FindWhatYouNeed()看样子是自定义函数,可有没有再说这个函数的内容,
    你说叫我怎么用呀!
      

  4.   

    又有所进展!应该用函数FindText() CFindReplaceDialog* pDlg = CFindReplaceDialog::GetNotifier(lParam);
        ASSERT(pDlg != NULL);    if (pDlg->IsTerminating())
        {
            pDlg = NULL;    }
    else if (pDlg->FindNext())
    {
    FindText(pDlg->GetFindString(),FALSE,FALSE);
            
    }
    return 1;
    大小问题还是有:
    那就是,查找总是从鼠标所在地方开始,而且是始终向前查找,而且不能循环。要让他也能向后,并能循环才行,而且查找菜单中选择了方向也是无用的,
    看来还是需要什么样的代码才行。-----------------------------
    给个提示:如果用的是
        else if (pFindReplace->FindNext())
    {
    if(FindText(pFindReplace->GetFindString(),FALSE,FALSE))
    AdjustDialogPosition(pFindReplace);  
             }
    return 0;
    }
    就可以,但你必须知道:AdjustDialogPosition()函数是CRichEditView类才有的。
    所以我不能用。
    ---------------------------
    现在要怎么样才能使查找循环并正确的从适当的位置开始?
      

  5.   

    -----------------------------------------------------------------
    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.
    注意最后两行的说明,你应该写一个消息函数来处理真正的查找/替换工作。
      

  6.   

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

  7.   

    AdjustDialogPosition好象只是调整窗口位置,不至于挡住被选择的字符串。请查看CFindReplaceDialog::SearchDown()函数的功能,可能对查找方向有作用。
      

  8.   

    AdjustDialogPosition()在CEditView中无法使用,你需要自己写一个类似的函数!
    我刚刚知道!实际上CEditViEW已经包含了cfindreplacedialog的支持,只是没有显示出来罢了,
    你可以将ceditrichviewI对应的edit菜单内容(包括菜单的id)拷贝到ceditview中,你就明白了
    ------------------------
    我已经解决了这个问题!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;
    }
      

  9.   

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