我的是SDI工程,因为还有其他功能要实现,所以不得以在SDI中的对话框中添加视类对象来做这个报表。但是添加CFormView后发现执行程序时,它要我选择视类文档类型,有点搞不懂! 你是如何添加CFormView的?贴出来看看。//类声明片段 class CMyDlg : public CDialog { // Construction public: CStatic m_RptBk; UINT m_nVScrollPos; CMyView *m_pView;//修改了OnInitDialog添加视类 BOOL CMyDlg::OnInitDialog() { CDialog::OnInitDialog(); UINT TargetCtrlID = IDS_TEST; CWnd *pWnd = this->GetDlgItem(TargetCtrlID); CRect RectTargetCtrl; pWnd->GetWindowRect(RectTargetCtrl); this->ScreenToClient(RectTargetCtrl); m_pView = (CMyView*)RUNTIME_CLASS(CMyView)->CreateObject(); //在目标位置动态创建视图 if (NULL==m_pView) { return FALSE; } m_pView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, RectTargetCtrl, this, TargetCtrlID); // TODO: Add extra initialization hereCSDN ((CScrollBar*)GetDlgItem(IDC_SCROLLBAR2))->SetScrollRange(0,100,TRUE); ((CScrollBar*)GetDlgItem(IDSB_VER))->SetScrollRange(0,100,TRUE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }这种情况我一点击视类就会断言报错
我的是SDI工程,因为还有其他功能要实现,所以不得以在SDI中的对话框中添加视类对象来做这个报表。但是添加CFormView后发现执行程序时,它要我选择视类文档类型,有点搞不懂! 你是如何添加CFormView的?贴出来看看。//类声明片段 class CMyDlg : public CDialog { // Construction public: CStatic m_RptBk; UINT m_nVScrollPos; CMyView *m_pView;//修改了OnInitDialog添加视类 BOOL CMyDlg::OnInitDialog() { CDialog::OnInitDialog(); UINT TargetCtrlID = IDS_TEST; CWnd *pWnd = this->GetDlgItem(TargetCtrlID); CRect RectTargetCtrl; pWnd->GetWindowRect(RectTargetCtrl); this->ScreenToClient(RectTargetCtrl); m_pView = (CMyView*)RUNTIME_CLASS(CMyView)->CreateObject(); //在目标位置动态创建视图 if (NULL==m_pView) { return FALSE; } m_pView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, RectTargetCtrl, this, TargetCtrlID); // TODO: Add extra initialization hereCSDN ((CScrollBar*)GetDlgItem(IDC_SCROLLBAR2))->SetScrollRange(0,100,TRUE); ((CScrollBar*)GetDlgItem(IDSB_VER))->SetScrollRange(0,100,TRUE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }这种情况我一点击视类就会断言报错对了,我调试了,发现在OnMouseActivate中比较它的父窗口和父框架窗口,即 CFrameWnd* pParentFrame = GetParentFrame(); if (pParentFrame != NULL) { // eat it if this will cause activation ASSERT(pParentFrame == pDesktopWnd || pDesktopWnd->IsChild(pParentFrame)); // either re-activate the current view, or set this view to be active CView* pView = pParentFrame->GetActiveView();因为基于对话框没有父框架窗口所以没有断言错误,而SDI有父框架即框架窗口,而父窗口是MyDlg,所以会出错! 我的目的是需要CFormView在其上摆上编辑框控件,不需要关联文档的,怎么办,麻烦您指导!
在需要的父窗口的OnCreate函数中,调用uView的Create方法创建,指定位置和大小
然后,新建一个视图类:CMyView,派生自CView。
然后,在对话框类CCreateViewDlg上定义一个视图类指针:CMyView *m_pView;
为了使得视图创建在指定的区域,在对话框上放一个静态文本控件,资源ID为IDC_STATIC_VIEW。
最后,在对话框的OnInitDialog函数里添加如下代码:
BOOL CCreateViewDlg::OnInitDialog()
{
.............................................................................................
.............................................................................................
// TODO: 在此添加额外的初始化代码
UINT TargetCtrlID = IDC_STATIC_VIEW;
CWnd *pWnd = this->GetDlgItem(TargetCtrlID);
CRect RectTargetCtrl;
pWnd->GetWindowRect(RectTargetCtrl);
this->ScreenToClient(RectTargetCtrl);
m_pView = (CMyView*)RUNTIME_CLASS(CMyView)->CreateObject();
//在目标位置动态创建视图
if (NULL==m_pView)
{
return FALSE;
}
m_pView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, RectTargetCtrl, this, TargetCtrlID);
return TRUE; // 除非将焦点设置到控件,否则返回TRUE
}
你是如何添加CFormView的?贴出来看看。
我的是SDI工程,因为还有其他功能要实现,所以不得以在SDI中的对话框中添加视类对象来做这个报表。但是添加CFormView后发现执行程序时,它要我选择视类文档类型,有点搞不懂!
你是如何添加CFormView的?贴出来看看。//类声明片段
class CMyDlg : public CDialog
{
// Construction
public:
CStatic m_RptBk;
UINT m_nVScrollPos;
CMyView *m_pView;//修改了OnInitDialog添加视类
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
UINT TargetCtrlID = IDS_TEST;
CWnd *pWnd = this->GetDlgItem(TargetCtrlID);
CRect RectTargetCtrl;
pWnd->GetWindowRect(RectTargetCtrl);
this->ScreenToClient(RectTargetCtrl);
m_pView = (CMyView*)RUNTIME_CLASS(CMyView)->CreateObject();
//在目标位置动态创建视图
if (NULL==m_pView)
{
return FALSE;
}
m_pView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, RectTargetCtrl, this, TargetCtrlID); // TODO: Add extra initialization hereCSDN
((CScrollBar*)GetDlgItem(IDC_SCROLLBAR2))->SetScrollRange(0,100,TRUE);
((CScrollBar*)GetDlgItem(IDSB_VER))->SetScrollRange(0,100,TRUE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}这种情况我一点击视类就会断言报错
你是如何添加CFormView的?贴出来看看。//类声明片段
class CMyDlg : public CDialog
{
// Construction
public:
CStatic m_RptBk;
UINT m_nVScrollPos;
CMyView *m_pView;//修改了OnInitDialog添加视类
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
UINT TargetCtrlID = IDS_TEST;
CWnd *pWnd = this->GetDlgItem(TargetCtrlID);
CRect RectTargetCtrl;
pWnd->GetWindowRect(RectTargetCtrl);
this->ScreenToClient(RectTargetCtrl);
m_pView = (CMyView*)RUNTIME_CLASS(CMyView)->CreateObject();
//在目标位置动态创建视图
if (NULL==m_pView)
{
return FALSE;
}
m_pView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, RectTargetCtrl, this, TargetCtrlID); // TODO: Add extra initialization hereCSDN
((CScrollBar*)GetDlgItem(IDC_SCROLLBAR2))->SetScrollRange(0,100,TRUE);
((CScrollBar*)GetDlgItem(IDSB_VER))->SetScrollRange(0,100,TRUE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}这种情况我一点击视类就会断言报错对了,我调试了,发现在OnMouseActivate中比较它的父窗口和父框架窗口,即
CFrameWnd* pParentFrame = GetParentFrame();
if (pParentFrame != NULL)
{
// eat it if this will cause activation
ASSERT(pParentFrame == pDesktopWnd || pDesktopWnd->IsChild(pParentFrame)); // either re-activate the current view, or set this view to be active
CView* pView = pParentFrame->GetActiveView();因为基于对话框没有父框架窗口所以没有断言错误,而SDI有父框架即框架窗口,而父窗口是MyDlg,所以会出错!
我的目的是需要CFormView在其上摆上编辑框控件,不需要关联文档的,怎么办,麻烦您指导!
如果用对话框做的话,实现你要的可编辑表格只需要一个ClistCtrl的扩展类就可以啊。