刚才看了个贴子:
想要将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 类不成功。大家有什么好办法???
想要将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 类不成功。大家有什么好办法???
解决方案 »
- 急。。。如何利用socket传输数据库记录集
- 静态控件里显示文字怎么才能换行!
- 弱弱地问,CListCtrl 控件中每个ITEM项目是不是单独的窗口啊,还是全部是CListCtrl绘制出来的?
- 请教如何在SDI的视图中动态创建一个控件,小弟新手,请路过神仙指点
- 加速键问题
- 高分求Overlap I/O实现源代码
- CTreeCtrl控件的消息ON_NOTIFY(NM_RCLICK, IDC_TREE1, OnRclickTree1)怎么得到鼠标位置?
- CListCtrl中如何知道当前选择已改变?
- MSDN有中文版的?
- 哪位知道mfc使用activex时他是怎样处理的?
- 再开一贴,解决CFindReplaceDialog类创建的查找对话框的使用问题,(连同另一贴共200分)!?
- 关于在全屏模式的程序中使用热键激活自己程序的问题
CMyFindDlg dlg(a,b,......);
好像并不要什么构造函数。
那个是不是可能是继承了CFileDialog里的构造函数。而到了用CFindReplaceDialog做基类,
它的构造函数我不太清楚,只在MSDN里查到了它的Create函数的参数。所以你看上面我才有:
public: //CMyFindDlg的构造,参照CFindReplaceDialog的Create参数。
CMyFindDlg( BOOL bFindDialogOnly,
LPCTSTR lpszFindWhat,
LPCTSTR lpszReplaceWith = NULL,
DWORD dwFlags = FR_DOWN,
CWnd* pParentWnd = NULL );
。。
就是想继承他的构造函数。就像CcolorDialog做基类派生的新类CMycolorDlg后只要CMycolorDlg dlg就行了。我也就是想要这样。
你说的CMyFindDlg dlg(a,b,......);
加参数,我恐怕自己做不来呀。
上面的CMycolorDlg dlg似乎不行,看来必须有参数才行。那么要怎么写呀?
所以不能用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。该怎么办???
LPCTSTR lpszReplaceWith, DWORD dwFlags, CWnd* pParentWnd )
{
return CFindReplaceDialog::Create(bFindDialogOnly, lpszFindWhat,
lpszReplaceWith, dwFlags, pParentWnd);
}
CMyFindDlg::Create(BOOL bFindDialogOnly, LPCTSTR lpszFindWhat,
LPCTSTR lpszReplaceWith, DWORD dwFlags, CWnd* pParentWnd )
:CFindReplaceDialog::Create(bFindDialogOnly, lpszFindWhat,
lpszReplaceWith, dwFlags, pParentWnd);
{
}
呢!
m_pMyFindDialog= new CFindReplaceDialog();
m_pMyFindDialog->Create(TRUE,NULL,NULL,FR_DOWN,this);
m_pMyFindDialog->SetActiveWindow();
m_pMyFindDialog->ShowWindow(TRUE);
可以出来呀!
那对于查找,一样吧!也要写个什么,调用
FindNext
GetNotifier
GetFindString
GetReplaceString
IsTerminating
MatchCase
MatchWholeWord
ReplaceAll
ReplaceCurrent
SearchDown
这个类对象的函数????看人家,在函数
LRESULT CMainFrame::OnFindDialogMessage(WPARAM wParam, LPARAM lParam)
里,调用都成功了,我的怎么不行呢?
http://expert.csdn.net/Expert/topic/1235/1235207.xml?temp=.901211
http://expert.csdn.net/Expert/topic/1235/1235211.xml?temp=.8234522
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.
注意最后两行的说明,你应该写一个消息函数来处理真正的查找/替换工作。
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!"); //测试用
}不知说明白没有,我试过了,可以的。
根据是上一贴英文的资料所述内容。
而且这个查找功能应该有一定的查找对象啊,比如如果你使用的是CEditView或CRichEditView,他就是在编辑器的buffer中查找,但是你用的是CView吧?那你是在什么中查找呢?我可能没看全你的内容,所述不知重复与否。
而且如果是CRichEditView做基类,那就可以用函数AdjustDialogPosition()了。
该写查找代码的地方用
if(FindText(pFindReplace->GetFindString(),FALSE,FALSE))
AdjustDialogPosition(pFindReplace);
就可以了!
------------因为有个例子就是这样的。
但现在视图类的基类是CEditView,我就不知道怎么写了。光用FindText(pFindReplace->GetFindString(),FALSE,FALSE),
效果出来就是:
比如,我输入了3行s
ssssssssssssss
ssssssssssssssss *
ssssssssssssss
把鼠标放到*的地方,查找ss,
那么就是从*的前面一个ss开始,一直往前,
不断的点查找下一个,就一直往前,
到了最前面就停住了。不能循环!!!
---------------------------------------
你说呢!
------------------------------
我已经解决了这个问题!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;
}
这个先结了,剩下的问题都到:http://expert.csdn.net/Expert/topic/1235/1235211.xml?temp=2.567691E-02里解决。谢谢大家。