VC按钮切换界面

  1. void CMainFrame::OnIMan()   
  2. {  
  3.  // TODO: Add your command handler code here  
  4.  CRect   cr;     
  5.   GetClientRect(&cr);     
  6.   CSize   paneSize1(200,   100);     
  7.    
  8.  CCreateContext   Context;     
  9.   Context.m_pNewViewClass=RUNTIME_CLASS(out);     
  10.  Context.m_pCurrentDoc=GetActiveDocument();   
  11.   Context.m_pCurrentFrame=this;     
  12.   Context.m_pNewDocTemplate=NULL;     
  13.   Context.m_pLastView=(CView*)m_splitter.GetPane(0,0);     
  14.   m_splitter.DeleteView(0,   1);     
  15.   m_splitter.CreateView(0,   1,RUNTIME_CLASS(in),paneSize1,   &Context);     
  16.   in   *pView=(in*)m_splitter.GetPane(0,1);     
  17.   pView->GetParentFrame()->RecalcLayout();      
  18.   m_splitter.RecalcLayout();     
  19.  pView->OnInitialUpdate();       
  20.  m_splitter.SetActivePane(0,1);  
  21. }  
  22. void CMainFrame::OnPan()   
  23. {  
  24.  // TODO: Add your command handler code here  
  25.  CRect   cr;     
  26.   GetClientRect(&cr);     
  27.   CSize   paneSize1(200,   100);     
  28.    
  29.  CCreateContext   Context;     
  30.   Context.m_pNewViewClass=RUNTIME_CLASS(in);     
  31.  Context.m_pCurrentDoc=GetActiveDocument();     
  32.   Context.m_pCurrentFrame=this;     
  33.   Context.m_pNewDocTemplate=NULL;     
  34.   Context.m_pLastView=(CView*)m_splitter.GetPane(0,0);     
  35.   m_splitter.DeleteView(0,   1);     
  36.   m_splitter.CreateView(0,   1,RUNTIME_CLASS(out),paneSize1,   &Context);     
  37.   out   *pView=(out*)m_splitter.GetPane(0,1);     
  38.   pView->GetParentFrame()->RecalcLayout();      
  39.   m_splitter.RecalcLayout();     
  40.  pView->OnInitialUpdate();       
  41.  m_splitter.SetActivePane(0,1);  
  42. }  
  43. 可以看到这里的函数是定义在CMainFrame.cpp文件中的。这里因为上面程序要进行界面控制,所以定义在CMainFrame.cpp文件中方便很多。那么要通过按钮响应这个函数,可以直接调用,代码如下:void mianban::OnIn()   
  44. {  
  45.  // TODO: Add your control notification handler code here  
  46.  CMainFrame *pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;  
  47.   pFrame->OnMan();  
  48. }   
  49. void mianban::OnOut()   
  50. {  
  51.  // TODO: Add your control notification handler code here  
  52.  CMainFrame *pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;  
  53.   pFrame->OnPan();  
  54. }  
  55. OK,现在直接通过两个按钮就可以实现两个界面的转换。  
前两天写了个数据库操作的小程序。程序里用到了按钮切换界面的功能。为了方便以后查看,现在将功能总结如下:

先来看看效果:

程序中就是通过 DATA Find 和DATA In 来切换两个不同的页面。

界面的划分和固定,在上篇日志已经详细介绍了,这里就不再说了,直接实现切换功能。

首先在OnCreateClient()函数里初始化界面,代码如下:

[cpp]  view plain copy
  1. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)   
  2. {  
  3.  // TODO: Add your specialized code here and/or call the base class  
  4.  m_splitter.CreateStatic(this,1,2);  
  5.     m_splitter.CreateView(0,0,RUNTIME_CLASS(mianban),CSize(250,100),pContext);  
  6.  m_splitter.CreateView(0,1,RUNTIME_CLASS(in),CSize(100,100),pContext);  
  7.  return TRUE;  
  8. }  

然后再mianban界面上添加两个按钮进行切换:

现在就为两个按钮进行响应:代码如下:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值