VC按钮切换界面
2014-12-27 14:24
260 查看
void CMainFrame::OnIMan()
{
// TODO: Add your command handler code here
CRect cr;
GetClientRect(&cr);
CSize paneSize1(200, 100);
CCreateContext Context;
Context.m_pNewViewClass=RUNTIME_CLASS(out);
Context.m_pCurrentDoc=GetActiveDocument();
Context.m_pCurrentFrame=this;
Context.m_pNewDocTemplate=NULL;
Context.m_pLastView=(CView*)m_splitter.GetPane(0,0);
m_splitter.DeleteView(0, 1);
m_splitter.CreateView(0, 1,RUNTIME_CLASS(in),paneSize1, &Context);
in *pView=(in*)m_splitter.GetPane(0,1);
pView->GetParentFrame()->RecalcLayout();
m_splitter.RecalcLayout();
pView->OnInitialUpdate();
m_splitter.SetActivePane(0,1);
}
void CMainFrame::OnPan()
{
// TODO: Add your command handler code here
CRect cr;
GetClientRect(&cr);
CSize paneSize1(200, 100);
CCreateContext Context;
Context.m_pNewViewClass=RUNTIME_CLASS(in);
Context.m_pCurrentDoc=GetActiveDocument();
Context.m_pCurrentFrame=this;
Context.m_pNewDocTemplate=NULL;
Context.m_pLastView=(CView*)m_splitter.GetPane(0,0);
m_splitter.DeleteView(0, 1);
m_splitter.CreateView(0, 1,RUNTIME_CLASS(out),paneSize1, &Context);
out *pView=(out*)m_splitter.GetPane(0,1);
pView->GetParentFrame()->RecalcLayout();
m_splitter.RecalcLayout();
pView->OnInitialUpdate();
m_splitter.SetActivePane(0,1);
}
可以看到这里的函数是定义在CMainFrame.cpp文件中的。这里因为上面程序要进行界面控制,所以定义在CMainFrame.cpp文件中方便很多。那么要通过按钮响应这个函数,可以直接调用,代码如下:void mianban::OnIn()
{
// TODO: Add your control notification handler code here
CMainFrame *pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
pFrame->OnMan();
}
void mianban::OnOut()
{
// TODO: Add your control notification handler code here
CMainFrame *pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
pFrame->OnPan();
}
OK,现在直接通过两个按钮就可以实现两个界面的转换。
前两天写了个数据库操作的小程序。程序里用到了按钮切换界面的功能。为了方便以后查看,现在将功能总结如下:
先来看看效果:
程序中就是通过 DATA Find 和DATA In 来切换两个不同的页面。
界面的划分和固定,在上篇日志已经详细介绍了,这里就不再说了,直接实现切换功能。
首先在OnCreateClient()函数里初始化界面,代码如下:
[cpp] view
plaincopy
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
m_splitter.CreateStatic(this,1,2);
m_splitter.CreateView(0,0,RUNTIME_CLASS(mianban),CSize(250,100),pContext);
m_splitter.CreateView(0,1,RUNTIME_CLASS(in),CSize(100,100),pContext);
return TRUE;
}
然后再mianban界面上添加两个按钮进行切换:
现在就为两个按钮进行响应:代码如下:
{
// TODO: Add your command handler code here
CRect cr;
GetClientRect(&cr);
CSize paneSize1(200, 100);
CCreateContext Context;
Context.m_pNewViewClass=RUNTIME_CLASS(out);
Context.m_pCurrentDoc=GetActiveDocument();
Context.m_pCurrentFrame=this;
Context.m_pNewDocTemplate=NULL;
Context.m_pLastView=(CView*)m_splitter.GetPane(0,0);
m_splitter.DeleteView(0, 1);
m_splitter.CreateView(0, 1,RUNTIME_CLASS(in),paneSize1, &Context);
in *pView=(in*)m_splitter.GetPane(0,1);
pView->GetParentFrame()->RecalcLayout();
m_splitter.RecalcLayout();
pView->OnInitialUpdate();
m_splitter.SetActivePane(0,1);
}
void CMainFrame::OnPan()
{
// TODO: Add your command handler code here
CRect cr;
GetClientRect(&cr);
CSize paneSize1(200, 100);
CCreateContext Context;
Context.m_pNewViewClass=RUNTIME_CLASS(in);
Context.m_pCurrentDoc=GetActiveDocument();
Context.m_pCurrentFrame=this;
Context.m_pNewDocTemplate=NULL;
Context.m_pLastView=(CView*)m_splitter.GetPane(0,0);
m_splitter.DeleteView(0, 1);
m_splitter.CreateView(0, 1,RUNTIME_CLASS(out),paneSize1, &Context);
out *pView=(out*)m_splitter.GetPane(0,1);
pView->GetParentFrame()->RecalcLayout();
m_splitter.RecalcLayout();
pView->OnInitialUpdate();
m_splitter.SetActivePane(0,1);
}
可以看到这里的函数是定义在CMainFrame.cpp文件中的。这里因为上面程序要进行界面控制,所以定义在CMainFrame.cpp文件中方便很多。那么要通过按钮响应这个函数,可以直接调用,代码如下:void mianban::OnIn()
{
// TODO: Add your control notification handler code here
CMainFrame *pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
pFrame->OnMan();
}
void mianban::OnOut()
{
// TODO: Add your control notification handler code here
CMainFrame *pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
pFrame->OnPan();
}
OK,现在直接通过两个按钮就可以实现两个界面的转换。
前两天写了个数据库操作的小程序。程序里用到了按钮切换界面的功能。为了方便以后查看,现在将功能总结如下:
先来看看效果:
程序中就是通过 DATA Find 和DATA In 来切换两个不同的页面。
界面的划分和固定,在上篇日志已经详细介绍了,这里就不再说了,直接实现切换功能。
首先在OnCreateClient()函数里初始化界面,代码如下:
[cpp] view
plaincopy
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
m_splitter.CreateStatic(this,1,2);
m_splitter.CreateView(0,0,RUNTIME_CLASS(mianban),CSize(250,100),pContext);
m_splitter.CreateView(0,1,RUNTIME_CLASS(in),CSize(100,100),pContext);
return TRUE;
}
然后再mianban界面上添加两个按钮进行切换:
现在就为两个按钮进行响应:代码如下:
相关文章推荐
- VC按钮切换界面
- VC++ 通过INI配置文件,实现多国语言切换界面
- VC.NET界面编程中关于的ToolBar(工具栏)的编程应用(二)2008/07/01 19:22 上回说到给工具栏上添加IE风格的下拉菜单按钮,我们通过设置工具栏按钮的风格已经完成了下拉菜单按钮的添加,现在我们准备为下拉菜单按钮中响应下拉箭头部分的实现
- VC界面美化之按钮
- 关于用phonegap 3.0+ 打包后sencha touch按钮点击切换动画延迟接近一秒的以及界面闪烁的解决方案
- VC界面美化之按钮
- Android 实现点击两个按钮,原地切换界面
- VC界面美化之按钮
- 一个Activity,用handleMessage(Message msg) 切换不同界面,主界面按钮不响应
- viewpager通过点击按钮方式切换界面失效的解决办法
- VC++实现切换按钮
- vc对话框编辑界面左下角有个小按钮,可以直接测试更改的效果
- 简单仿照主流新闻客户端界面一(标题栏按钮弹性按钮切换
- VC之按钮控件位置大小界面设置
- 关于用phonegap 3.0+ 打包后sencha touch按钮点击切换动画延迟接近一秒的以及界面闪烁的解决方案
- iOS 顶部几个按钮切换界面代码
- VC界面美化之按钮
- 仿微信6.0的界面按钮切换产生渐变效果
- VC++界面编程之--自定义CButton(按钮)皮肤