SDI工程,手动创建CGisShowTreate类,继承CWnd.
  参见http://topic.csdn.net/u/20080919/22/beede080-e5ba-4e6a-a337-c72667e2c2f3.html?seed=1350084183
http://topic.csdn.net/u/20080920/18/35469eac-3b72-4da3-8e24-7b45dfafc905.html
  都没有解决问题.
  只从CWnd继承,不从CView或是CFrameWnd继承.
  显示的窗体(没有最大化时),是正常显示,但是最大化后,除开原来显示的区域,其他区域像是死机的显示.而且鼠标响应消息只能在那些死机区域内响应,正常显示的区域不能响应,望高手指教,分不够在给.上面两个帖子都没有想要的答案.已经两天没解决了.急.
  CMainFrame类下的两个虚函数(其中m_wndView是CTestView声明的对象 CTestView m_wndView,CTestView是从classwizard中从generic CWnd继承过来) 
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 

// let the view have first crack at the command 
if (m_wndView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) 
return TRUE; // otherwise, do default handling 
return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); 
} BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) 

if( !CFrameWnd::PreCreateWindow(cs) ) 
return FALSE; 
// TODO: Modify the Window class or styles here by modifying 
//  the CREATESTRUCT cs cs.dwExStyle &= ~WS_EX_CLIENTEDGE; 
cs.lpszClass = AfxRegisterWndClass(0); 
return TRUE; 
} 两个消息映射 
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 

if (CFrameWnd::OnCreate(lpCreateStruct) == -1) 
return -1; 
// create a view to occupy the client area of the frame 
if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, 
CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL)) 

TRACE0("Failed to create view window\n"); 
return -1; 
} if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP 
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || 
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) 

TRACE0("Failed to create toolbar\n"); 
return -1;      // fail to create 
} if (!m_wndStatusBar.Create(this) || 
!m_wndStatusBar.SetIndicators(indicators, 
  sizeof(indicators)/sizeof(UINT))) 

TRACE0("Failed to create status bar\n"); 
return -1;      // fail to create 
} // TODO: Delete these three lines if you don't want the toolbar to 
//  be dockable 
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); 
EnableDocking(CBRS_ALIGN_ANY); 
DockControlBar(&m_wndToolBar); return 0; 
} void CMainFrame::OnSetFocus(CWnd* pOldWnd) 

// forward focus to the view window 
m_wndView.SetFocus(); 
} CTestView类 
class CTestView : public CWnd 

// Construction 
public: 
CTestView(); 
// Overrides 
// ClassWizard generated virtual function overrides 
//{{AFX_VIRTUAL(CTestView) 
public: 
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL); 
protected: 
virtual BOOL PreCreateWindow(CREATESTRUCT& cs); 
//}}AFX_VIRTUAL public: 
virtual ~CTestView(); // Generated message map functions 
protected: 
//{{AFX_MSG(CTestView) 
afx_msg void OnLButtonDown(UINT nFlags, CPoint point); 
afx_msg void OnLButtonUp(UINT nFlags, CPoint point); 
afx_msg void OnShowWindow(BOOL bShow, UINT nStatus); 
//}}AFX_MSG 
DECLARE_MESSAGE_MAP() 
private: 
HDC            m_WindowDC; 
}; .cpp文件中 
BEGIN_MESSAGE_MAP(CTestView, CWnd) 
//{{AFX_MSG_MAP(CTestView) 
ON_WM_LBUTTONDOWN() 
ON_WM_LBUTTONUP() 
ON_WM_SHOWWINDOW() 
//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
两个虚函数 
BOOL CTestView::PreCreateWindow(CREATESTRUCT& cs) 

// TODO: Add your specialized code here and/or call the base class if (!CWnd::PreCreateWindow(cs)) 
return FALSE; cs.dwExStyle |= WS_EX_CLIENTEDGE; 
cs.style &= ~WS_BORDER; 
cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL); return TRUE; 
} BOOL CTestView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 

// TODO: Add your specialized code here and/or call the base class if (!CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext)) 
        return FALSE;     return TRUE; 

解决方案 »

  1.   

    同样的代码,在创建SDI时,去掉View/Document那个选项就可以,高手帮忙,不解
      

  2.   

    使用文档-视图模型的视图窗口有一些特定的约定,例如初始化、特定的消息,建议CTestView从CView继承,并至少实现OnDraw虚函数,即使什么也不干。直接从CWnd继承本身也没有问题,但是有些消息必须要处理,比如父窗口的OnSize、OnActive,还有重绘的问题。
      

  3.   

    建议看看CView的实现代码,
    CVIEW 在处理消息的时候是要和FRAME想联系的
    没看到你的完整的代码和跟踪一下的,谁也不好说
    如楼上兄弟说的, 很多虚函数CVIEW都有自己的处理,
    处理办法就是:
    还是从CVIEW 里面继承一个VIEW,然后把你那个CWND  贴在VIEW 上面是一样的
      

  4.   

    没有文档/视图的SDI我用多了,都没有问题的。从你上面的代码看都是正常的,但是,你主楼提到的“CGisShowTreate”是怎么回事儿?严重怀疑你没有贴出真正的关键代码。
      

  5.   

    写错了,CGisShowTreate实际上和CTestView一样的,我另外写的一个测试程序,没有用CTestView而用的是CGisShowTreate,但是消息映射的代码和虚函数的代码都是一样的
      

  6.   

    TO:CHLX2003
      你说的办法我试过了,还是一样的效果. 
      

  7.   

    代码没有问题,我怀疑是在CMainFrame::OnCreate中创建CChlidView窗体时,
    if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
    CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
    {
    TRACE0("Failed to create view window\n");
    return -1;
    }
    参数有问题,导致执行后,只有部分区域能够响应鼠标点击消息CMainFrame类
    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
    return -1;

    if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
    CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
    {
    TRACE0("Failed to create view window\n");
    return -1;
    } if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
    | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
    !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    {
    TRACE0("Failed to create toolbar\n");
    return -1;      // fail to create
    } if (!m_wndStatusBar.Create(this) ||
    !m_wndStatusBar.SetIndicators(indicators,
      sizeof(indicators)/sizeof(UINT)))
    {
    TRACE0("Failed to create status bar\n");
    return -1;      // fail to create
    } // TODO: Delete these three lines if you don't want the toolbar to
    //  be dockable
    m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
    EnableDocking(CBRS_ALIGN_ANY);
    FloatControlBar(&m_wndToolBar, CPoint(200,200)); return 0;
    }BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
    {
    if( !CFrameWnd::PreCreateWindow(cs) )
    return FALSE;
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs

    cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
    cs.lpszClass = AfxRegisterWndClass(0); return TRUE;
    }BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
    {
    // let the view have first crack at the command
    if (m_wndView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
    return TRUE;

    // otherwise, do default handling
    return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
    }void CMainFrame::OnSetFocus(CWnd* pOldWnd) 
    {
    m_wndView.SetFocus();

    // TODO: Add your message handler code here

    }CTestView类
    BOOL CTestView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
    {
    if (!CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext))
            return FALSE;

        return TRUE;
    }BOOL CTestView::PreCreateWindow(CREATESTRUCT& cs) 
    {
    if (!CWnd::PreCreateWindow(cs))
    return FALSE;

    cs.dwExStyle |= WS_EX_CLIENTEDGE;
    cs.style &= ~WS_BORDER;
    cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
    ::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL);

    return TRUE;
    }void CTestView::OnShowWindow(BOOL bShow, UINT nStatus) 
    {
        CWnd::OnShowWindow(bShow, nStatus);
    }void CTestView::OnSize(UINT nType, int cx, int cy) 
    {
        CWnd::OnSize(nType, cx, cy);
    }void CTestView::OnPaint() 
    {
    CPaintDC dc(this); // device context for painting
    }
    /////////////////////////////////////////////////////////////////////////////
    // CTestViewmessage handler
    void CTestView::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    AfxMessageBox("CGisShowTreate::OnLButtonDown");
        CWnd::OnLButtonDown(nFlags, point);
    }void CTestView::OnLButtonUp(UINT nFlags, CPoint point)
    {
    AfxMessageBox("CGisShowTreate::OnLButtonUp");
    CWnd::OnLButtonUp(nFlags,point);
    }
      

  8.   

    CChildView类可以响应列出的消息,除了鼠标点击消息只能部分响应外