class CMYView : public CView
{
DECLARE_DYNCREATE(CMYView)
protected:
CMYView(); // 动态创建所使用的受保护的构造函数
virtual ~CMYView();
public:
virtual void OnDraw(CDC* pDC); // 重写以绘制该视图
DECLARE_MESSAGE_MAP()
};
void CVectorView::OnDraw(CDC* pDC)
{
CRect rc;
//当前的位置
GetClientRect(&rc);
//pDC->MoveTo(p1);
//pDC->LineTo(p2);
}
#define IDD_DIALOG_MY 98989 //Dlg的ID
#define IDC_DRAW_VIEW 10983 //临时控件ID
class CMYDlg : public CDialog
{
DECLARE_DYNAMIC(CMYDlg)
public:
CMYDlg(CWnd* pParent = NULL); // 标准构造函数
virtual ~CMYDlg();
// 对话框数据
enum { IDD = IDD_DIALOG_MY };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
DECLARE_MESSAGE_MAP()
CMYView* m_pMyView;
virtual BOOL OnInitDialog();
private:
void SetViewPosition();
CRect m_rcVector;
};
BOOL CMYDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetViewPosition();
return TRUE;
}
void CMYDlg::SetPlotPosition()
{
CWnd *pTmpWnd = GetDlgItem(IDC_DRAW_VIEW);
if(pTmpWnd)
{
pTmpWnd->GetWindowRect(&m_rcVector);
ScreenToClient(&m_rcVector);
}
CCreateContext context;
CWnd* pParentWnd= this;
//DYNAMIC_DOWNCAST将CDYBitDoc转换成CDocument转换失败为NULL
context.m_pCurrentDoc= DYNAMIC_DOWNCAST(CDYBitDoc,GetCurrentDoc());//将在其上创建视图的文档
context.m_pNewViewClass= RUNTIME_CLASS(CMYView);//待创建的视图的CRuntimeClass
//在父窗口上创建View
m_pMyView= (CMYView*)((CFrameWnd*)pParentWnd)->CreateView(&context);
//判断m_pMyView是否可用
ASSERT(m_pMyView);
//将临时空间隐藏
pTmpWnd->ShowWindow(SW_HIDE);
//将要显示的view显示
m_pMyView->ShowWindow(SW_NORMAL);
//将要显示的窗口移动到临时窗口的位置
m_pMyView->MoveWindow(m_rcVector);
}