MFC 创建动态切分窗口的问题

陪你一起去看海 2014-01-26 11:21:32
初学者在学MFC时 尝试去写一个切分窗口的问题 采用的是动态切分 程序虽运行出来了 但是窗口无法切分

代码如下 哪位前辈来帮解决一下这个问题
#include <afxwin.h>
#include <afxext.h>
#include "resource.h"
class CMyFrame :public CFrameWnd
{
public :
DECLARE_MESSAGE_MAP()
DECLARE_DYNCREATE(CMyFrame)
public :
CSplitterWnd m_wndSplitter;
public :
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
virtual BOOL OnCreateClient(LPCREATESTRUCT lpCreateStruct,CCreateContext *pContext);
};
IMPLEMENT_DYNCREATE(CMyFrame,CFrameWnd)
BEGIN_MESSAGE_MAP(CMyFrame,CFrameWnd)
ON_WM_CREATE()
END_MESSAGE_MAP()
class CMyView :public CView
{
public :
DECLARE_DYNCREATE(CMyView)
virtual void OnDraw(CDC *pDC);
};
IMPLEMENT_DYNCREATE(CMyView,CView)
class CMyApp : public CWinApp
{
public :
virtual BOOL InitInstance();
};
CMyApp theApp;
BOOL CMyApp :: InitInstance()
{
CMyFrame *pWnd =new CMyFrame();
pWnd->LoadFrame( IDR_MAINFRM );
m_pMainWnd = pWnd;
m_pMainWnd->ShowWindow( SW_SHOW );
m_pMainWnd->UpdateWindow( );
return TRUE;
}
int CMyFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CFrameWnd::OnCreate(lpCreateStruct);
ModifyStyleEx( WS_EX_CLIENTEDGE, 0 );
return TRUE;
}
void CMyView ::OnDraw(CDC *pDC)
{
pDC->TextOut( 50, 50, "View 1" );
}
BOOL CMyFrame::OnCreateClient(LPCREATESTRUCT lpCreateStruct,CCreateContext *pContext)
{
CCreateContext context;

context.m_pNewViewClass =
RUNTIME_CLASS( CMyView );

m_wndSplitter.Create( this, 2, 2,
CSize( 50, 50), &context );
return TRUE;
}

...全文
305 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 7 楼 schlafenhamster 的回复:
不需要 CreateView 因为context.m_pNewViewClass = RUNTIME_CLASS( CMyView ); 已经 有了 所有的 View 就是 这个 view 可能 大小 不对, 试试: m_Splitter.SetRowInfo(0, Hei, 50); m_Splitter.SetRowInfo(1, Hei, 50); m_Splitter.SetColumnInfo(0, Wid, 50); m_Splitter.SetColumnInfo(1, Wid, 50);
呃 加入之后可以使用了 但是为什么加入这么一段语句后就正常了 能给我讲一下吗?
  • 打赏
  • 举报
回复
引用 5 楼 schlafenhamster 的回复:
Dynamic splitter windows, with views of the same class, allow the user to split a window into multiple panes at will and then scroll different panes to see different parts of the document.
英文水平差 这段略有不懂之处
schlafenhamster 2014-01-28
  • 打赏
  • 举报
回复
不需要 CreateView 因为context.m_pNewViewClass = RUNTIME_CLASS( CMyView ); 已经 有了 所有的 View 就是 这个 view 可能 大小 不对, 试试: m_Splitter.SetRowInfo(0, Hei, 50); m_Splitter.SetRowInfo(1, Hei, 50); m_Splitter.SetColumnInfo(0, Wid, 50); m_Splitter.SetColumnInfo(1, Wid, 50);
schlafenhamster 2014-01-27
  • 打赏
  • 举报
回复
Dynamic splitter windows, with views of the same class, allow the user to split a window into multiple panes at will and then scroll different panes to see different parts of the document.
  • 打赏
  • 举报
回复
引用 3 楼 VisualEleven 的回复:
http://blog.csdn.net/visualeleven/article/details/6460564 你说的是这个吧~
和这个正相反 是在CFrameWnd类的OnCreateClient中创建的
Eleven 2014-01-26
  • 打赏
  • 举报
回复
http://blog.csdn.net/visualeleven/article/details/6460564 你说的是这个吧~
  • 打赏
  • 举报
回复
引用 1 楼 schlafenhamster 的回复:
光是 : m_wndSplitter.Create( this, 2, 2, CSize( 50, 50), &context ); 不行 还要 CreateView
不是静态切分窗口中时才需要的吗
schlafenhamster 2014-01-26
  • 打赏
  • 举报
回复
光是 : m_wndSplitter.Create( this, 2, 2, CSize( 50, 50), &context ); 不行 还要 CreateView

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧