XTToolkitPro使用

XTToolkitPro使用... 1

开发环境... 2

添加SDI程序的CommandBar和MenuBar支持... 2

定制toolbars和menus的支持... 3

添加自定义的主题支持... 5

添加Docking Panes支持... 6

发现定义在XTPDeprecated.h中的符号,为废弃符号,修改为新符号即可... 9

添加智能菜单支持... 9

添加自定义特性的派生控件... 9

 


Visual Studio 2008 + XTToolkitPro v11.2


1、  创建MFC的SDI应用程序

2、  在stdafx.h添加

#include <XTToolkitPro.h> // Xtreme Toolkit Pro component library

3、  修改mainfrm.h的CMainFrame基类,MDI对应为

CXTPMDIFrameWnd

class CMainFrame : public CXTPFrameWnd

4、  修改CMainFrame::OnCreate函数

    // Initialize the command bars

    if (!InitCommandBars())

        return -1;

 

    // Get a pointer to the command bars object.

    CXTPCommandBars* pCommandBars = GetCommandBars();

    if(pCommandBars == NULL)

    {

        TRACE0("Failed to create command bars object./n");

        return -1;      // fail to create

    }

 

    // Add the menu bar

    CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(

        _T("Menu Bar"), IDR_MAINFRAME);

    if(pMenuBar == NULL)

    {

        TRACE0("Failed to create menu bar./n");

        return -1;      // fail to create

    }

 

    // Create ToolBar

    CXTPToolBar* pToolBar = (CXTPToolBar*)

        pCommandBars->Add(_T("Standard"), xtpBarTop);

    if (!pToolBar || !pToolBar->LoadToolBar(IDR_MAINFRAME))

    {

        TRACE0("Failed to create toolbar/n");

        return -1;

    }

 

    // Set Office 2003 Theme

    CXTPPaintManager::SetTheme(xtpThemeOffice2003);

注释掉以下几行

     //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("未能创建工具栏/n");

     //      return -1;      // 未能创建

     //}

     /*m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);

     EnableDocking(CBRS_ALIGN_ANY);

     DockControlBar(&m_wndToolBar);*/

5、  如果需要重载CMainFrame::PreTranslateMessage和CMainFrame::OnCmdMsg,修改如下

BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)

{

    // TODO: Add your specialized code here and/or call the base class

 

    return CXTPMDIFrameWnd::PreTranslateMessage(pMsg);

}

 

BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode,

    void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)

{

    // TODO: Add your specialized code here and/or call the base class

 

    return CXTPMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);

}

6、  编译运行,出现Offiice 2003主题风格的应用程序

 

1、

在CMainFrm类增加响应ON_COMMAND的消息

XTP_ID_CUSTOMIZE

支持

在mainfrm.cpp中修改

BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)

    //{{AFX_MSG_MAP(CMainFrame)

    ON_WM_CREATE()

    //}}AFX_MSG_MAP

    ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)

END_MESSAGE_MAP()

在mainfrm.h中修改

    //{{AFX_MSG(CMainFrame)

    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);

    //}}AFX_MSG

    afx_msg void OnCustomize();

    DECLARE_MESSAGE_MAP()

2、  在mainfrm.cpp中增加

void CMainFrame::OnCustomize()

{

    // Get a pointer to the command bars object.

    CXTPCommandBars* pCommandBars = GetCommandBars();

    if(pCommandBars != NULL)

    {

        // Instanciate the customize dialog object.

        CXTPCustomizeSheet dlg(pCommandBars);

 

        // Add the options page to the customize dialog.

        CXTPCustomizeOptionsPage pageOptions(&dlg);

        dlg.AddPage(&pageOptions);

 

        // Add the commands page to the customize dialog.

        CXTPCustomizeCommandsPage* pCommands = dlg.GetCommandsPage();

        pCommands->AddCategories(IDR_MDISAMTYPE);

 

        // Use the command bar manager to initialize the

        // customize dialog.

        pCommands->InsertAllCommandsCategory();

        pCommands->InsertBuiltInMenus(IDR_MDISAMTYPE);

        pCommands->InsertNewMenuCategory();

 

        // Dispaly the dialog.

        dlg.DoModal();

    }

}

3、  添加CMainFrm类的对commandbar和menubar的定制配置序列化支持

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

    ...

 

    // Load the previous state for toolbars and menus.

    LoadCommandBars(_T("CommandBars"));

 

    return 0;

}

void CMainFrame::OnClose()

{

    // Save the current state for toolbars and menus.

    SaveCommandBars(_T("CommandBars"));

    CMDIFrameWnd::OnClose();

}

4、  资源包含,查看rc2资源文件代码,添加xttoolkitpro.rc,在资源附加目录中添加xttoolkitpro.rc所在目录

5、  编译运行,发现定制化工具栏和菜单的资源没有加载进来,如图标、字符串等,解决方法是修改字符资源语言为英文(这里编译的是英文资源的lib库,根据自己需要也可以编译中文资源的lib库)


1、  选择父主题类,如

CXTPDefaultTheme to inherit Office 2000 theme

CXTPOfficeTheme to inherit Office XP theme

CXTPOffice2003Theme to inherit Office 2003 theme

CXTPNativeXPTheme to inherit Native XP theme

2、  实现自定义主题类的接口,接口函数为DrawCommandBarGripper

class CDoubleGripperTheme : public CXTPDefaultTheme

{

    virtual CSize DrawCommandBarGripper(

        CDC* pDC, CXTPCommandBar* pBar, BOOL bDraw);

};

 

// DrawCommandBarGripper function.

// if bDraw if FALSE must return gripper size.

// if bDraw is TRUE must draw gripper.

CSize CDoubleGripperTheme::DrawCommandBarGripper(CDC* pDC,

    CXTPCommandBar* pBar, BOOL bDraw)

{

    // If Toolbar is vertical docked

    if (pBar->GetPosition() == xtpBarRight ||

        pBar->GetPosition() == xtpBarLeft)

    {

        if (bDraw)

        {

            CXTPClientRect rc(pBar);

            Draw3dRect(pDC, CRect(3, 3, rc.right - 3, 6),

                COLOR_BTNHILIGHT, COLOR_3DSHADOW);

            Draw3dRect(pDC, CRect(3, 7, rc.right - 3, 10),

                COLOR_BTNHILIGHT, COLOR_3DSHADOW);

        }

        return CSize(0, 10);

    }

    // if Toolbar is horizontal  docked

    else

    if (pBar->GetPosition() == xtpBarTop ||

        pBar->GetPosition() == xtpBarBottom)

    {

        CXTPClientRect rc(pBar);

        if (bDraw)

        {

            Draw3dRect(pDC, CRect(3, 3, 6, rc.bottom - 3),

                COLOR_BTNHILIGHT, COLOR_3DSHADOW);

            Draw3dRect(pDC, CRect(7, 3, 10, rc.bottom - 3),

                COLOR_BTNHILIGHT, COLOR_3DSHADOW);

        }

        return CSize(10, 0);

    }

    else return CXTPDefaultTheme::DrawCommandBarGripper(pDC, pBar, bDraw);

}

3、  运行查看效果

支持

1、  在CMainFrame类中添加CXTPDockingPaneManager成员

// Attributes

public:

    CXTPDockingPaneManager m_paneManager;

2、  添加字符串资源

IDR_PANE_OPTIONS       61446    Options

IDR_PANE_PROPERTIES    61447    Properties

3、  在CMainFrame::OnCreate中添加

// Initialize the docking pane manager and set the

// initial them for the docking panes.  Do this only after all

// control bars objects have been created and docked.

m_paneManager.InstallDockingPanes(this);

m_paneManager.SetTheme(xtpPaneThemeOffice);

 

// Create docking panes.

CXTPDockingPane* pwndPane1 = m_paneManager.CreatePane(

    IDR_PANE_OPTIONS, CRect(0, 0,200, 120), dockLeftOf);

CXTPDockingPane* pwndPane2 = m_paneManager.CreatePane(

    IDR_PANE_PROPERTIES, CRect(0, 0,200, 120), dockBottomOf, pwndPane1)

4、  运行查看Docking Panes效果

5、  绑定窗口控件类到Docking Panes中

6、  添加CMainFrame的窗口控件成员

// Attributes

public:

    CStatic m_wndOptions;

    CEdit m_wndProperties;

7、  添加OnDockingPaneNotify函数处理,绑定窗口控件成员到Docking Panes上

BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)

    //{{AFX_MSG_MAP(CMainFrame)

    ON_WM_CREATE()

    //}}AFX_MSG_MAP

    ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, OnDockingPaneNotify)

END_MESSAGE_MAP()

 

LRESULT CMainFrame::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)

{

    if (wParam == XTP_DPN_SHOWWINDOW)

    {

        CXTPDockingPane* pPane = (CXTPDockingPane*)lParam;

 

        if (!pPane->IsValid())

        {

            switch (pPane->GetID())

            {

            case IDR_PANE_PROPERTIES:

                {

                    if (m_wndProperties.GetSafeHwnd() == 0)

                    {

                        m_wndProperties.Create(WS_CHILD|

                            ES_AUTOVSCROLL|ES_MULTILINE,

                            CRect(0, 0, 0, 0), this, 0);

                    }

                    pPane->Attach(&m_wndProperties);

                    break;

                }

            case IDR_PANE_OPTIONS:

                {

                    if (m_wndOptions.GetSafeHwnd() == 0)

                    {

                        m_wndOptions.Create(_T("/n/nOptions"),

                            WS_CHILD|WS_CLIPCHILDREN|

                            WS_CLIPSIBLINGS|SS_CENTER,

                            CRect(0, 0, 0, 0), this, 0);

                    }

                    pPane->Attach(&m_wndOptions);

                    break;

                }

            }

        }

        return TRUE;

    }

    return FALSE;

}

8、  添加Bitmap图片资源,2个图标大小33x15

9、  添加CMainFrame::OnCreate中

int nIDIcons[] = {IDR_PANE_OPTIONS, IDR_PANE_PROPERTIES};

    m_paneManager.SetIcons(IDB_BITMAP_ICONS, nIDIcons,

_countof(nIDIcons), RGB(0, 255, 0));

10、              添加Docking Panes的序列化支持

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

    ...

 

    // Load the previous state for docking panes.

    CXTPDockingPaneLayout layoutNormal(&m_paneManager);

    if (layoutNormal.Load(_T("NormalLayout")))

    {

        m_paneManager.SetLayout(&layoutNormal);

    }

    return 0;

}

void CMainFrame::OnClose()

{

    // Save the current state for docking panes.

    CXTPDockingPaneLayout layoutNormal(&m_paneManager);

    m_paneManager.GetLayout(&layoutNormal);

    layoutNormal.Save(_T("NormalLayout"));

    CMDIFrameWnd::OnClose();

}

11、              运行查看带图标的Docking Panes效果

 

1、  定义想隐藏的菜单ID数组

static UINT uHideCmds[] =

{

    ID_FILE_PRINT, ID_FILE_PRINT_PREVIEW, ID_WINDOW_CASCADE

};

2、  在CMainFrame::OnCreate中添加

// Hide array of commands

pCommandBars->HideCommands(uHideCmds, _countof(uHideCmds));

 

// Set "Always Show Full Menus" option to the FALSE

XTP_COMMANDBARS_OPTIONS* pOptions = pCommandBars->GetCommandBarsOptions();

pOptions->bAlwaysShowFullMenus = FALSE;

3、  运行查看结果


1、  派生控件继承自CXTPControlButton, CXTPControlPopup, CXTPControlComboBox, CXTPControlEdit,例如派生ComboBox实现输入字符自动更新为大写,ComboBox内嵌了ComboBoxEditCtrl,重载OnChar实现自动更新

2、  重载实现CXTPControlComboBoxEditCtrl的OnChar成员

class CControlComboBoxEditEx : public CXTPControlComboBoxEditCtrl

{

public:

    afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);

 

    DECLARE_MESSAGE_MAP()

};

 

BEGIN_MESSAGE_MAP(CControlComboBoxEditEx, CXTPControlComboBoxEditCtrl)

    ON_WM_CHAR()

END_MESSAGE_MAP()

 

void CControlComboBoxEditEx::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)

{

    CString strChar((TCHAR)nChar), strUpper((TCHAR)nChar);

    strUpper.MakeUpper();

 

    if (strChar != strUpper) ReplaceSel(strUpper, TRUE);

    else CXTPControlComboBoxEditCtrl::OnChar(nChar, nRepCnt, nFlags);

}

3、  重载实现CControlComboBoxEx的CreateEditControl成员

class CControlComboBoxEx: public CXTPControlComboBox

{

    DECLARE_XTP_CONTROL(CControlComboBoxEx)

public:

    CXTPControlComboBoxEditCtrl* CreateEditControl()

    {

        return new CControlComboBoxEditEx();

    }

};

 

IMPLEMENT_XTP_CONTROL(CControlComboBoxEx, CXTPControlComboBox)

4、  增加CControlComboBoxEx新成员对内嵌CXTPControlComboBoxEditCtrl进行数据交换操作

class CControlComboBoxEx: public CXTPControlComboBox

{

...

 

protected:

    void Copy(CXTPControl* pControl, BOOL bRecursive = FALSE);

    virtual void DoPropExchange(CXTPPropExchange* pPX);

 

protected:

    CString m_strMask;

};

 

void CControlComboBoxEx::Copy(CXTPControl* pControl, BOOL bRecursive)

{

    ASSERT_KINDOF(CControlComboBoxEx, pControl);

 

    m_strMask = ((CControlComboBoxEx*)pControl)->m_strMask;

 

    CXTPControlComboBox::Copy(pControl, bRecursive);

}

 

void CControlComboBoxEx::DoPropExchange(CXTPPropExchange* pPX)

{

    CXTPControlComboBox::DoPropExchangepPX);

 

    PX_String(pPX, _T("Mask"), m_strMask);

}

5、  在CMainFrame类的OnCreateControl成员里面添加CControlComboBoxEx控件,资源ID为ID_POPUP_COMBO

BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)

    ON_XTP_CREATECONTROL()

END_MESSAGE_MAP()

 

int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)

{

    if (lpCreateControl->nID == ID_POPUP_COMBO)

    {

        CXTPControlComboBox* pComboFind = (CXTPControlComboBox*)CControlComboBoxEx::CreateObject();

        pComboFind->SetDropDownListStyle();

        pComboFind->SetFlags(xtpFlagManualUpdate);

 

        lpCreateControl->pControl = pComboFind;

        return TRUE;

    }

    return FALSE;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值