请教各位,我已将窗口分割成两个窗口,如何实现两个窗口之间的信息同步。
具体如下:本人建立了一个单文档,工程名为4。由CFORMVIEW派生出CCONTROLVIEW和CSHOWVIEW类。分别创建两个对话框与CCONTROLVIEW和CSHOWVIEW类相对应。窗口已经被静态分割成两个窗口。现CCONTROLVIEW所对应的窗口中有两幅位图,其中一幅位图个用鼠标拖动来改变其位置也可通过键盘上的上下左右键来使其上下左右移动。现在想实现CSHOWVIEW所对应的窗口显示的内容和CCONTROLVIEW所对应的窗口有相同的信息。CCONTROLVIEW所对应的窗口中图片移动情况也在CSHOWVIEW所对应的窗口显示。请指点?????
ControlView.cpp文件我加入的代码如下:
void CControlView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CControlView)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
DDX_Control(pDX,IDC_STATIC1,m_img);
}
BEGIN_MESSAGE_MAP(CControlView, CFormView)
//{{AFX_MSG_MAP(CControlView)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CControlView diagnostics#ifdef _DEBUG
void CControlView::AssertValid() const
{
CFormView::AssertValid();
}void CControlView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
// CControlView message handlers
void CControlView::OnLButtonDown(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default
//当鼠标左键按下时记录鼠标位置 
m_oldpt=point;
CFormView::OnLButtonDown(nFlags, point);
}void CControlView::OnLButtonUp(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default
//当鼠标左键抬起时记录鼠标位置 
m_newpt=point;
    //计算鼠标的移动 
    CSize sz;
sz=m_newpt-m_oldpt;
//坐标变换
CRect rcImg;//图片矩形
m_img.GetWindowRect(&rcImg);
this->ScreenToClient(&rcImg);
int x=rcImg.left+sz.cx;
int y=rcImg.top+sz.cy;
//将图片作和鼠标相同的移动
m_img.SetWindowPos(NULL,x,y,0,0,SWP_NOSIZE);
CFormView::OnLButtonUp(nFlags, point);
}BOOL CControlView::PreTranslateMessage(MSG* pMsg) 
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message== WM_KEYDOWN) 

CRect rc; 
m_img.GetWindowRect(&rc); 
this->ScreenToClient(&rc);//屏幕坐标到用户坐标转换 
int x=rc.left; 
int y=rc.top; 
switch(pMsg->wParam) 

case 37://左移 
m_img.SetWindowPos(NULL,x-10,y,0,0,SWP_NOSIZE); 
break; 
case 38://上 
m_img.SetWindowPos(NULL,x,y-10,0,0,SWP_NOSIZE); 
break; 
    case 39://右 
m_img.SetWindowPos(NULL,x+10,y,0,0,SWP_NOSIZE); 
break; 
case 40://下 
m_img.SetWindowPos(NULL,x,y+10,0,0,SWP_NOSIZE); 
break; 

}
return CFormView::PreTranslateMessage(pMsg);
}MainFrm.cpp中我加入的代码如下:
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
CCreateContext* pContext)
{  //创建一个静态分栏窗口,分为一行二列 
     m_wndSplitter1.CreateStatic(this,1,2);

//将CControlView连接到0行0列窗格上
m_wndSplitter1.CreateView(0,0,RUNTIME_CLASS(CControlView),CSize(1200,100), pContext);
//将CShowView连接到0行1列窗格上
m_wndSplitter1.CreateView(0,1,RUNTIME_CLASS(CShowView),CSize(100,100),pContext); 

 return TRUE;