Xtreme ToolkitPro taskpanel创建

1)
新建一个MFC SDI工程

2)
// stdafx.h
#include   // Codejock Software Components

3)
// MainFrm.h
// class CMainFrame : public CFrameWnd改为
class CMainFrame : public CXTPFrameWnd

//用于创建ToolBox的成员
public:
    // m_wndSplitter分割窗口,在切分的窗口内创建ToolBox,
// 是否能直接在View中创建ToolBox我还没有测试
    CXTSplitterWnd m_wndSplitter;
// 生成ToolBox效果的CXTPTaskPanel类
    CXTPTaskPanel m_wndTaskPanel;
// 创建ToolBox,初始化一些风格
    BOOL CreateTaskPanel();
// 初始化ToolBox数据
    void ResetToolboxItems();
// 新建ToolBox的Group栏
    CXTPTaskPanelGroup* CreateToolboxGroup(UINT nID);
// 在OnCreateClient中切分窗口,调用CreateTaskPanel创建ToolBox
virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
4)
在字符串资源用新建以下资源,用于ToolBox中的组名和Toolbox名
ID_TOOLBOXFOLDER_DATA   "Data"
ID_TOOLBOXFOLDER_PROPERTYPANES "PropertyPanes"
ID_TOOLBOXITEM_OLEDBDATAADAPTER "OleDbDataAdapter"
ID_TOOLBOXITEM_POINTER  "Pointer"
... ...

5)
// MainFrm.cpp 
MainFrm.cpp中主要是修改以下代码
void CMainFrame::ResetToolboxItems()
{
    //首先清除原有数据,然后重新写入
//一些如ID_TOOLBOXFOLDER_DATA的宏,是字符串资源
m_wndTaskPanel.GetGroups()->Clear(FALSE);

CXTPTaskPanelGroup* pFolderPropertyPanes = CreateToolboxGroup(ID_TOOLBOXFOLDER_PROPERTYPANES);

CXTPTaskPanelGroup* pFolderData = CreateToolboxGroup(ID_TOOLBOXFOLDER_DATA);
pFolderData->AddLinkItem(ID_TOOLBOXITEM_DATASET                 ,26);
pFolderData->AddLinkItem(ID_TOOLBOXITEM_OLEDBDATAADAPTER        ,27);

CXTPTaskPanelGroup* pFolderComponents = CreateToolboxGroup(ID_TOOLBOXFOLDER_PROPERTYPANES);
pFolderComponents->AddLinkItem(ID_TOOLBOXITEM_DATASET     ,34);
pFolderComponents->AddLinkItem(ID_TOOLBOXITEM_OLEDBDATAADAPTER              ,35);

CreateToolboxGroup(ID_TOOLBOXFOLDER_GENERAL);

pFolderPropertyPanes->SetExpanded(TRUE);
}

//用于在ToolBox中新增组
CXTPTaskPanelGroup* CMainFrame::CreateToolboxGroup(UINT nID)
{
CXTPTaskPanelGroup* pFolder = m_wndTaskPanel.AddGroup(nID);

CXTPTaskPanelGroupItem* pPointer = pFolder->AddLinkItem(ID_TOOLBOXITEM_POINTER, 0);
pPointer->SetItemSelected(TRUE);
pPointer->AllowDrag(FALSE);
pPointer->AllowDrop(FALSE);
pFolder->SetIconIndex(IDR_MAINFRAME);

return pFolder;
}

//创建TaskPanel,并设置一些风格
BOOL CMainFrame::CreateTaskPanel()
{
if (!m_wndTaskPanel.Create(WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_TABSTOP, CRect(0, 0, 0, 0), &m_wndSplitter, m_wndSplitter.IdFromRowCol(0, 0)))
return FALSE;

m_wndTaskPanel.SetOwner(this);

//设置Toolbox使用的位图
m_wndTaskPanel.GetImageManager()->SetIcons(IDB_TOOLBOXICONS, 0, 0, CSize(16, 16));
m_wndTaskPanel.SetBehaviour(xtpTaskPanelBehaviourToolbox);
m_wndTaskPanel.SetTheme(xtpTaskPanelThemeToolbox);
m_wndTaskPanel.SetSelectItemOnFocus(TRUE);
m_wndTaskPanel.AllowDrag(TRUE);

m_wndSplitter.SetColumnInfo(0, 210, 0);

return TRUE;
}

// 在OnCreateClient中切分窗口,调用CreateTaskPanel创建ToolBox
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
    m_wndSplitter.CreateStatic(this, 1, 2);
m_wndSplitter.ModifyStyleEx(0, WS_EX_CONTROLPARENT);    

m_wndSplitter.CreateView(0, 1, pContext->m_pNewViewClass, CSize(300, 0), pContext);
SetActiveView((CView*)m_wndSplitter.GetDlgItem(m_wndSplitter.IdFromRowCol(0, 1)));

    if (!CreateTaskPanel())
return FALSE;

    return TRUE;

    // 一定要删除return CXTPFrameWnd::OnCreateClient(lpcs, pContext);否则无法生成分割窗口
    // return CXTPFrameWnd::OnCreateClient(lpcs, pContext);
}

// OnCreate中调用ResetToolboxItems
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
... ...
    ResetToolboxItems();
return 0;
}

6)
IDB_TOOLBOXICONS
 
 
Toolbox也可以使用真彩色图标
步骤如下:
1)
将真彩色icon添加到vs2005工程中
2)
BOOL CMainFrame::CreateTaskPanel()
{
if (!m_wndTaskPanel.Create(WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_TABSTOP, CRect(0, 0, 0, 0), &m_wndSplitter, m_wndSplitter.IdFromRowCol(0, 0)))
return FALSE;

m_wndTaskPanel.SetOwner(this);

m_wndTaskPanel.GetImageManager()->SetIcon(IDI_ICON1, 0);
m_wndTaskPanel.GetImageManager()->SetIcon(IDI_ICON2, 1);
m_wndTaskPanel.GetImageManager()->SetIcon(IDI_ICON3, 2);

m_wndTaskPanel.SetBehaviour(xtpTaskPanelBehaviourToolbox);
m_wndTaskPanel.SetTheme(xtpTaskPanelThemeShortcutBarOffice2007);
m_wndTaskPanel.SetSelectItemOnFocus(TRUE);
m_wndTaskPanel.AllowDrag(TRUE);
m_wndTaskPanel.SetIconSize(CSize(32, 32));
m_wndTaskPanel.SetItemLayout(xtpTaskItemLayoutImagesWithTextBelow);

m_wndSplitter.SetColumnInfo(0, 210, 0);

return TRUE;
}
 
 
CXTPTaskPanel也可以直接放到View中
步骤如下:
1)
新建一个SDI

2)
View.h中
CXTPTaskPanel m_wndTaskPanel;
CXTPTaskPanelGroup* CreateToolboxGroup(UINT nID);

3)
View.cpp中

void CToolBox2View::OnInitialUpdate()
{
... ...
// TODO: Add your specialized code here and/or call the base class
if (!m_wndTaskPanel.Create(WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_TABSTOP,
rc, this, 1231))
return ;
m_wndTaskPanel.SetOwner(this);

m_wndTaskPanel.GetImageManager()->SetIcon(IDI_ICON1, 0);
m_wndTaskPanel.GetImageManager()->SetIcon(IDI_ICON2, 1);
m_wndTaskPanel.GetImageManager()->SetIcon(IDI_ICON3, 2);

m_wndTaskPanel.SetBehaviour(xtpTaskPanelBehaviourToolbox);
m_wndTaskPanel.SetTheme(xtpTaskPanelThemeShortcutBarOffice2007);
m_wndTaskPanel.SetSelectItemOnFocus(TRUE);
m_wndTaskPanel.AllowDrag(TRUE);
m_wndTaskPanel.SetIconSize(CSize(32, 32));
m_wndTaskPanel.SetItemLayout(xtpTaskItemLayoutImagesWithTextBelow);

///////////////////////////////////////////////////////////////////////
m_wndTaskPanel.GetGroups()->Clear(FALSE);

CXTPTaskPanelGroup* pFolderPropertyPanes = CreateToolboxGroup(ID_TOOLBOXFOLDER_PROPERTYPANES);
CXTPTaskPanelGroup* pFolderData = CreateToolboxGroup(ID_TOOLBOXFOLDER_DATA);
pFolderData->AddLinkItem(ID_TOOLBOXITEM_DATASET ,1);
pFolderData->AddLinkItem(ID_TOOLBOXITEM_OLEDBDATAADAPTER ,1);

CXTPTaskPanelGroup* pFolderComponents = CreateToolboxGroup(ID_TOOLBOXFOLDER_PROPERTYPANES);
pFolderComponents->AddLinkItem(ID_TOOLBOXITEM_DATASET ,2);
pFolderComponents->AddLinkItem(ID_TOOLBOXITEM_OLEDBDATAADAPTER ,1);

CreateToolboxGroup(ID_TOOLBOXFOLDER_GENERAL);
pFolderPropertyPanes->SetExpanded(TRUE);
}

CXTPTaskPanelGroup* CToolBox2View::CreateToolboxGroup(UINT nID)
{
CXTPTaskPanelGroup* pFolder = m_wndTaskPanel.AddGroup(nID);

CXTPTaskPanelGroupItem* pPointer = pFolder->AddLinkItem(ID_TOOLBOXITEM_POINTER, 0);
pPointer->SetItemSelected(TRUE);
pPointer->AllowDrag(FALSE);
pPointer->AllowDrop(FALSE);
pFolder->SetIconIndex(IDR_MAINFRAME);

return pFolder;
}

你可能感兴趣的:(Xtreme ToolkitPro taskpanel创建)