24小时热门版块排行榜    

查看: 144  |  回复: 0
当前主题已经存档。

zsglly

木虫 (著名写手)

[交流] 如何做出类似vc的workshop

我无意中在网上找到几个class,无须dll库就能轻松做出vc的workshop。不敢独享,特地把我的经验介绍出来,以供大家参考。

  

方法如下:

1.  将scbarg.h,scbarg.cpp,sizecbar.h,sizecbar.cpp,mybar.h,mybar.cpp文件copy到你的工程目录下,打开vc,将这几个文件添加进工程。

2.  打开stdafx.h文件,在其中加入:#include "sizecbar.h",#include "scbarg.h"。

3.  为CmainFrame类添加成员变量:CMyBar        m_wndMyBar。

4.  重载CMainFrame:estroyWindow(),在其中加入

       CString sProfile(_T("BarState");

       m_wndMyBar.SaveState(sProfile);

SaveBarState(sProfile);

5.  修改CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)如下:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

       if (CFrameWnd::OnCreate(lpCreateStruct) == -1)

              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

       }

       if (!m_wndMyBar.Create(_T("My Bar", this, 123))

   {

        TRACE0("Failed to create mybar\n";

        return -1;      // fail to create

       }

       // TODO: Delete these three lines if you don't want the toolbar to

       //  be dockable

       m_wndMyBar.SetBarStyle(m_wndMyBar.GetBarStyle() |

        CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

       m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);

       m_wndMyBar.EnableDocking(CBRS_ALIGN_ANY);  

       EnableDocking(CBRS_ALIGN_ANY);

       DockControlBar(&m_wndToolBar);

       DockControlBar(&m_wndMyBar, AFX_IDW_DOCKBAR_LEFT);

       CString sProfile(_T("BarState");

    if (VerifyBarState(sProfile))

    {

        m_wndMyBar.LoadState(sProfile);

        LoadBarState(sProfile);

    }

       return 0;

}

注:黑体部分为所加内容。

6.  在“查看”菜单下添加菜单项mybar,设其id为:ID_VIEW_MYBAR.

7.  为其添加CMainFrame::OnViewMybar(),CMainFrame::OnUpdateViewMybar(CCmdUI* pCmdUI)函数,内容为:

void CMainFrame::OnViewMybar()  

{

       // TODO: Add your command handler code here

       BOOL bShow = m_wndMyBar.IsVisible();

       ShowControlBar(&m_wndMyBar, !bShow, FALSE);

}

void CMainFrame::OnUpdateViewMybar(CCmdUI* pCmdUI)  

{

       // TODO: Add your command update UI handler code here

       pCmdUI->Enable();

       pCmdUI->SetCheck(m_wndMyBar.IsVisible());

}

编译运行即可,如果你想改变workshop中的cedit成员变量(如本例workshop中的树),只需改变mybar中的代码即可。

[ Last edited by 幻影无痕 on 2006-11-17 at 08:29 ]
回复此楼
做人要厚道啊!厚道啊!
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 zsglly 的主题更新
普通表情 高级回复 (可上传附件)
信息提示
请填处理意见