MFC选项卡制作,我要详细的步骤说明,可以一步一步来的
展开全部
是说的tabctrl嘛?
http://www.vckbase.com/document/viewdoc/?id=398
http://www.vckbase.com/document/viewdoc/?id=398
展开全部
我的代码 你可以参考一下
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
... ...
int nCtrlID = 1, nTabIndex = 0;
if ( !m_wndTab.Create( TCS_FOCUSNEVER|WS_VISIBLE|TCS_RIGHTJUSTIFY, CRect( 0, 0, 0, 0 ), &m_wndView, nCtrlID++ ) )
{
TRACE0("Failed to create m_wndTab \n");
return -1;
}
CFont tabFont;
tabFont.CreateFont(12,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,
"宋体");
m_wndTab.SetFont(&tabFont,true);
tabFont.Detach();
m_wndTab.InsertItem( nTabIndex++, "错误" );
if ( !m_wndErrEvent.Create( WS_VISIBLE|WS_BORDER|LVS_REPORT|LVS_NOSORTHEADER, CRect( 0, 0, 0, 0 ), &m_wndTab, nCtrlID++ ) )
{
TRACE0("Failed to create m_wndErrEvent \n");
return -1;
}
m_wndErrEvent.SetExtendedStyle( LVS_EX_FULLROWSELECT );
m_wndErrEvent.InsertColumn( 0, "时间" );
m_wndErrEvent.InsertColumn( 1, "错误事件" );
m_wndErrEvent.ShowWindow( SW_SHOW );
m_wndTab.InsertItem( nTabIndex++, "调试" );
if ( !m_wndDebugEvent.Create( WS_VISIBLE|WS_BORDER|LVS_REPORT|LVS_NOSORTHEADER, CRect( 0, 0, 0, 0 ), &m_wndTab, nCtrlID++ ) )
{
TRACE0("Failed to create m_wndDebugEvent \n");
return -1;
}
m_wndDebugEvent.SetExtendedStyle( LVS_EX_FULLROWSELECT );
m_wndDebugEvent.InsertColumn( 0, "时间" );
m_wndDebugEvent.InsertColumn( 1, "调试事件" );
m_wndErrEvent.ShowWindow( SW_HIDE );
m_wndDebugEvent.ShowWindow( SW_SHOW );
m_wndTab.SetCurSel( m_wndTab.GetItemCount() - 1 );
}
ChildView.h:
//{{AFX_MSG(CChildView)
afx_msg void OnPaint();
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG
afx_msg void OnSelChangeTab(NMHDR *pNotify,LRESULT *pResult);
DECLARE_MESSAGE_MAP()
ChildView.cpp:
BEGIN_MESSAGE_MAP(CChildView,CWnd )
//{{AFX_MSG_MAP(CChildView)
ON_WM_PAINT()
ON_WM_SIZE()
//}}AFX_MSG_MAP
ON_NOTIFY(TCN_SELCHANGE,1,OnSelChangeTab)
END_MESSAGE_MAP()
void CChildView::OnSize(UINT nType, int cx, int cy)
{
CWnd ::OnSize(nType, cx, cy);
if (IsWindow(((CMainFrame*)theApp.m_pMainWnd)->m_wndTab.m_hWnd))
{
CRect viewRect;
this->GetClientRect(viewRect);
((CMainFrame*)theApp.m_pMainWnd)->m_wndTab.MoveWindow(viewRect);
CRect tabRect;
((CMainFrame*)theApp.m_pMainWnd)->m_wndTab.GetClientRect(tabRect);
((CMainFrame*)theApp.m_pMainWnd)->m_wndTab.AdjustRect(FALSE,tabRect);
if (IsWindow(((CMainFrame*)theApp.m_pMainWnd)->m_wndDebugEvent.m_hWnd))
{
((CMainFrame*)theApp.m_pMainWnd)->m_wndDebugEvent.MoveWindow(tabRect);
}
if (IsWindow(((CMainFrame*)theApp.m_pMainWnd)->m_wndErrEvent.m_hWnd))
{
((CMainFrame*)theApp.m_pMainWnd)->m_wndErrEvent.MoveWindow(tabRect);
}
for ( int i = 0; i < 2; i++ )
{
((CMainFrame*)theApp.m_pMainWnd)->m_wndDebugEvent.SetColumnWidth( i, LVSCW_AUTOSIZE_USEHEADER );
((CMainFrame*)theApp.m_pMainWnd)->m_wndErrEvent.SetColumnWidth( i, LVSCW_AUTOSIZE_USEHEADER );
}
}
}
void CChildView::OnSelChangeTab(NMHDR *pNotify,LRESULT *pResult)
{
int cursel=((CMainFrame*)theApp.m_pMainWnd)->m_wndTab.GetCurSel();
if ( cursel == ((CMainFrame*)theApp.m_pMainWnd)->m_wndTab.GetItemCount() - 1 )
{
((CMainFrame*)theApp.m_pMainWnd)->m_wndDebugEvent.ShowWindow(SW_SHOW);
((CMainFrame*)theApp.m_pMainWnd)->m_wndErrEvent.ShowWindow(SW_HIDE);
}
else if ( cursel == 0 )
{
((CMainFrame*)theApp.m_pMainWnd)->m_wndDebugEvent.ShowWindow(SW_HIDE);
((CMainFrame*)theApp.m_pMainWnd)->m_wndErrEvent.ShowWindow(SW_SHOW);
}
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
... ...
int nCtrlID = 1, nTabIndex = 0;
if ( !m_wndTab.Create( TCS_FOCUSNEVER|WS_VISIBLE|TCS_RIGHTJUSTIFY, CRect( 0, 0, 0, 0 ), &m_wndView, nCtrlID++ ) )
{
TRACE0("Failed to create m_wndTab \n");
return -1;
}
CFont tabFont;
tabFont.CreateFont(12,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,
"宋体");
m_wndTab.SetFont(&tabFont,true);
tabFont.Detach();
m_wndTab.InsertItem( nTabIndex++, "错误" );
if ( !m_wndErrEvent.Create( WS_VISIBLE|WS_BORDER|LVS_REPORT|LVS_NOSORTHEADER, CRect( 0, 0, 0, 0 ), &m_wndTab, nCtrlID++ ) )
{
TRACE0("Failed to create m_wndErrEvent \n");
return -1;
}
m_wndErrEvent.SetExtendedStyle( LVS_EX_FULLROWSELECT );
m_wndErrEvent.InsertColumn( 0, "时间" );
m_wndErrEvent.InsertColumn( 1, "错误事件" );
m_wndErrEvent.ShowWindow( SW_SHOW );
m_wndTab.InsertItem( nTabIndex++, "调试" );
if ( !m_wndDebugEvent.Create( WS_VISIBLE|WS_BORDER|LVS_REPORT|LVS_NOSORTHEADER, CRect( 0, 0, 0, 0 ), &m_wndTab, nCtrlID++ ) )
{
TRACE0("Failed to create m_wndDebugEvent \n");
return -1;
}
m_wndDebugEvent.SetExtendedStyle( LVS_EX_FULLROWSELECT );
m_wndDebugEvent.InsertColumn( 0, "时间" );
m_wndDebugEvent.InsertColumn( 1, "调试事件" );
m_wndErrEvent.ShowWindow( SW_HIDE );
m_wndDebugEvent.ShowWindow( SW_SHOW );
m_wndTab.SetCurSel( m_wndTab.GetItemCount() - 1 );
}
ChildView.h:
//{{AFX_MSG(CChildView)
afx_msg void OnPaint();
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG
afx_msg void OnSelChangeTab(NMHDR *pNotify,LRESULT *pResult);
DECLARE_MESSAGE_MAP()
ChildView.cpp:
BEGIN_MESSAGE_MAP(CChildView,CWnd )
//{{AFX_MSG_MAP(CChildView)
ON_WM_PAINT()
ON_WM_SIZE()
//}}AFX_MSG_MAP
ON_NOTIFY(TCN_SELCHANGE,1,OnSelChangeTab)
END_MESSAGE_MAP()
void CChildView::OnSize(UINT nType, int cx, int cy)
{
CWnd ::OnSize(nType, cx, cy);
if (IsWindow(((CMainFrame*)theApp.m_pMainWnd)->m_wndTab.m_hWnd))
{
CRect viewRect;
this->GetClientRect(viewRect);
((CMainFrame*)theApp.m_pMainWnd)->m_wndTab.MoveWindow(viewRect);
CRect tabRect;
((CMainFrame*)theApp.m_pMainWnd)->m_wndTab.GetClientRect(tabRect);
((CMainFrame*)theApp.m_pMainWnd)->m_wndTab.AdjustRect(FALSE,tabRect);
if (IsWindow(((CMainFrame*)theApp.m_pMainWnd)->m_wndDebugEvent.m_hWnd))
{
((CMainFrame*)theApp.m_pMainWnd)->m_wndDebugEvent.MoveWindow(tabRect);
}
if (IsWindow(((CMainFrame*)theApp.m_pMainWnd)->m_wndErrEvent.m_hWnd))
{
((CMainFrame*)theApp.m_pMainWnd)->m_wndErrEvent.MoveWindow(tabRect);
}
for ( int i = 0; i < 2; i++ )
{
((CMainFrame*)theApp.m_pMainWnd)->m_wndDebugEvent.SetColumnWidth( i, LVSCW_AUTOSIZE_USEHEADER );
((CMainFrame*)theApp.m_pMainWnd)->m_wndErrEvent.SetColumnWidth( i, LVSCW_AUTOSIZE_USEHEADER );
}
}
}
void CChildView::OnSelChangeTab(NMHDR *pNotify,LRESULT *pResult)
{
int cursel=((CMainFrame*)theApp.m_pMainWnd)->m_wndTab.GetCurSel();
if ( cursel == ((CMainFrame*)theApp.m_pMainWnd)->m_wndTab.GetItemCount() - 1 )
{
((CMainFrame*)theApp.m_pMainWnd)->m_wndDebugEvent.ShowWindow(SW_SHOW);
((CMainFrame*)theApp.m_pMainWnd)->m_wndErrEvent.ShowWindow(SW_HIDE);
}
else if ( cursel == 0 )
{
((CMainFrame*)theApp.m_pMainWnd)->m_wndDebugEvent.ShowWindow(SW_HIDE);
((CMainFrame*)theApp.m_pMainWnd)->m_wndErrEvent.ShowWindow(SW_SHOW);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询