初学者
请教各位 如何添加查找对话框

解决方案 »

  1.   

    这个一个专门的类,属于非模式对话框。CFindReplaceDialog
    看MSDN吧,一时说不清。不过提醒你,注意两件事情:
    注册消息和实现!    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_MAP
    对话框的生成:
    void CRichEditView::InitFindReplaceDlg() 
    {
       if( NULL == m_pFRDlg )
       {
          m_pFRDlg = new CMyFindReplaceDlg();  // Must be created on the heap      m_pFRDlg->Create( TRUE, "", "", FR_DOWN, this );       m_pFRDlg->m_fr.lStructSize = sizeof(FINDREPLACE);
          m_pFRDlg->m_fr.hwndOwner = this->m_hWnd;
          m_pFRDlg->m_fr.lpstrFindWhat = m_pFRDlg->GetFindWhatStr();
          m_pFRDlg->m_fr.lpstrReplaceWith = m_pFRDlg->GetReplaceWithStr();
          m_pFRDlg->m_fr.wFindWhatLen =  m_pFRDlg->GetFindWhatStrLen();
          m_pFRDlg->m_fr.wReplaceWithLen =  m_pFRDlg->GetReplaceWithStrLen();
       }
    }
    上面都是例子,要自己研究。
      

  2.   

    CFindReplaceDialog  *dia=new CFindReplaceDialog; 
    dia->Create(true,"Program");
      

  3.   

    下面是我做过的,//Find通用对话框的消息响应函数
    LRESULT CHexView::OnFindHexMessage(WPARAM wParam, LPARAM lParam)
    {
    CFindReplaceDialog* pDlg = CFindReplaceDialog::GetNotifier(lParam);
        ASSERT(pDlg != NULL);
        
    if (pDlg->IsTerminating())
        {
            pDlg = NULL;
    this->bHexFirstSearchTime = TRUE;
        }
    else if ( pDlg->FindNext() )
    {   
              if(!FindText(pDlg->GetFindString(),TRUE,FALSE)) //调用FindText()进行查找
      {  //当没有找到的时候
             this->bHexFirstSearchTime = TRUE;
                 OnTextNotFound(pDlg->GetFindString());
             MessageBox("FIND Have reached the END,Cann't find it!");
      }
    }
    return 0;
    }主要是两个地方:
    pDlg->FindNext() 
    和FindText函数如果FindText不能满足你的要求,你还必须重载CEditView的这个FindText函数,实现你的功能。就说这么多。