http://www.codeproject.com/dialog/cfindreplacedialog.asp
Using the CFindReplaceDialog class

解决方案 »

  1.   

    不行啊,运行有错误,估计是自己不行,:(,这么多问题真不好意思了
    有4个错误:E:\YlxProjects\testa\testaView.cpp(26) : error C2065: 'm_FindDialogMessage' : undeclared identifier
    E:\YlxProjects\testa\testaView.cpp(39) : error C2758: 'm_pFindDialogMessage' : must be initialized in constructor base/member initializer list
            e:\ylxprojects\testa\testaview.h(56) : see declaration of 'm_pFindDialogMessage'
    E:\YlxProjects\testa\testaView.cpp(41) : error C2065: 'FindDialogMessage' : undeclared identifier
    E:\YlxProjects\testa\testaView.cpp(148) : error C2065: 'FindWhatYouNeed' : undeclared identifier
    Error executing cl.exe.testa.exe - 4 error(s), 0 warning(s)
    我照着那个程序弄的,是这样的选择菜单上的查找,弹出查找对话框。void CTestaView::OnFind()//创建对话框 ,没有问题,OK
    {
    // TODO: Add your command handler code here
    ASSERT(m_pFindDialog == NULL);
    m_pFindDialog = new CFindReplaceDialog();
    m_pFindDialog->Create(TRUE, "Initial Text", NULL, FR_DOWN, this);}LRESULT CTestaView::OnFindDialogMessage(WPARAM wParam, LPARAM lParam)//这个也是找那个程序改的,只不过换成了自己的类
    {
        ASSERT(m_pFindDialog != NULL);    // If the FR_DIALOGTERM flag is set,
        // invalidate the handle identifying the dialog box.
        if (m_pFindDialog->IsTerminating())
        {
            m_pFindDialog = NULL;
            return 0;
        }    // If the FR_FINDNEXT flag is set,
        // call the application-defined search routine
        // to search for the requested string.
        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);
        }    return 0;
    }
    带*的这句话是不是自定义函数呀,不太明白呀,就是自己怎么定义,能否举个例子另外我是这样加的这个:
    BEGIN_MESSAGE_MAP(CTestaView, CEditView)
    //{{AFX_MSG_MAP(CTestaView)
        ON_COMMAND(ID_FIND, OnFind)//这句是用classvizard生成创建对话框
        //}}AFX_MSG_MAP        的函数自己加上去的    ON_REGISTERED_MESSAGE(m_FindDialogMessage, OnFindDialogMessage)
    END_MESSAGE_MAP()//主要是加的这句我是在这个构造函数里赋的初值
    CTestaView::CTestaView()
    {
    // TODO: add construction code here
    FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);}
    另外,static const UINT m_pFindDialogMessage;这个我也定义在了CTestaView类里,但是它总是告诉我说定义找不到其他的我改的地方到是没有了。这篇文章没看太懂是不是,只要把“It is more user friendly when you remember ……”这段以上的搞懂就差不多能实现查找的功能了呢?麻烦了,:)
      

  2.   

    对了,补充一句,我是基于CEditView生成的程序,因为这个类可以打开txt类型的文件,所以我想打开一个文件,然后进行字符(串)的查找,可以做到吗?多帮忙了,初学者,:)