查找/替换对话框CFindReplaceDialog

来源:互联网 发布:黑魂3 防火女捏脸数据 编辑:程序博客网 时间:2024/06/05 01:51

 

      MSDN上的解释: 
      class CFindReplaceDialog : public CCommonDialog
       CFindReplaceDialog objects are modeless, allowing users to interact with other windows while they are on
 screen. 
      There are two kinds of CFindReplaceDialog objects: Find dialog boxes and Find/Replace dialog boxes.
      Although the dialog boxes allow the user to input search and search/replace strings, they do not perform any of
 the searching or replacing functions. You must add these to the application.
      To construct a CFindReplaceDialog object, use the provided constructor (which has no arguments). 
Since this is a modeless dialog box, allocate the object on the heap using the new operator, rather than on the stack.
        CFindReplaceDialog对象是非模态的,允许用户与屏幕上的窗口进行交互
     有两种CFindReplaceDialog对象:查找对话框和 查找/替换对话框
     尽管对话框允许用户输入查找/替换对话框,它们并不进行查找或替换,必须在应用中添加相关代码。
 
     以下为构造查找/替换对话框步骤:
 
    1)  初始化
          假如工程是基于对话框的, 则在‘ 工程Dlg.cpp’ 中添加一个指针全局变量、BOOL类型变量find、自定义的一个消息
 
          定义变量及注册消息
         CFindReplaceDialog *findReplaceDlg;   //  用以指向对话框资源
         BOOL find;   // 用以确定是查找对话框,还是查找/替换对话框
         static UINT WM_FINDMESSAGE=RegisterWindowMessage(FINDMSGSTRING);//  定义的新消息,执行查找/替换对话框时发送该消息
 
        在工程DLG.h中  给对话框添加一消息响应函数
CLASS 工程Dlg: public CDialog
{
public: afx_msg long OnFindReplace(WPARAM wParam,LPARAM lParam);
 CRichEditCtrl m_RichEdit;   //   在RichEdit控件中 实现查找替换功能
}
         同时,在‘工程Dlg.cpp’ 中添加消息函数映射       
         ON_REGISTERED_MESSAGE(WM_FINDMESSAGE,OnFindReplace)         
    2) 构造查找/替换对话框
       因为它是非模态的,所以必须用new操作符把它放于堆而不能放于栈中
 
       点击对话框的查找按钮,添加如下代码:(工程名称为Hello2) 
 
 
     点击替换按钮,添加如下代码:
 
 
 
   在DLG.cpp中添加消息响应函数OnFindReplace(WPARAM wParam, LPARAM lParam)
 
  
 
 
 
参考资料:
http://bk.chinaar.com/index.php?doc-view-76
http://book.csdn.net/bookfiles/565/10056518722.shtml
http://book.51cto.com/art/200810/92630.htm
http://www.codeproject.com/KB/dialog/cfindreplacedialog.aspx
http://blog.sina.com.cn/s/blog_6171ceb30100ex1d.html
http://www.vckbase.com/study/article/vc_chap/chap5_6.htm

如果此文对您有所帮助,还望点击一下以下网站:

    360导航

    2345导航        

   古典小说网,本人的网站
原创粉丝点击