翻譯|使用教程|編輯:鮑佳佳|2020-09-23 14:55:35.260|閱讀 648 次
概述:在版本19.2之前,不能夠將控件的主題應用于ToolkitPro控件(例如CXTPEdit,CXTPTree,CXTPListBox,CXTPListCtrl和CXTPPropertyGrid)中的滾動條。因為通用Windows控件擁有自己顯示和處理的滾動條的方式,并且覆蓋Windows通用控件的行為以及保持完全的向后兼容性在技術上非常具有挑戰性,因此導致需要考慮一定的可使用進的解決方案。本文介紹了關鍵點,并試圖回答可能出現的常見問題。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Xtreme Toolkit Pro是MFC開發中最全面界面控件套包,它提供了Windows開發所需要的11種主流的Visual C++ MFC控件,包括Command Bars、Controls、Chart Pro、Calendar、Docking Pane、Property Grid、Report Control、Shortcut Bar、Syntax Edit、Skin Framework 和Task Panel。如果對產品感興趣的話歡迎下載Xtreme Toolkit Pro最新試用版! 點擊獲取更多免費Xtreme Toolkit Pro教程、視頻、示例!
【同類產品推薦】
在版本19.2之前,不能夠將控件的主題應用于ToolkitPro控件(例如CXTPEdit,CXTPTree,CXTPListBox,CXTPListCtrl和CXTPPropertyGrid)中的滾動條。因為通用Windows控件擁有自己顯示和處理的滾動條的方式,并且覆蓋Windows通用控件的行為以及保持完全的向后兼容性在技術上非常具有挑戰性,因此導致需要考慮一定的可使用進的解決方案。本文介紹了關鍵點,并試圖回答可能出現的常見問題。
解決方案實際上,以下類保持不變,并且仍使用未應用主題的標準Windows滾動條:
為了能夠應用滾動條主題或自定義滾動條類,必須使用或派生新特殊適配器模板類的新控件類CXTPScrollable<Base>。
對于最常見的用例,將應用程序中使用的控件類名替換為對應的類名就足夠了,這些類名源自CXTPScrollable:
CXTPPropertyGrid這是一種特殊情況,它沒有其他CXTPScrollable派生版本,僅在內部使用新方法,保持完全向后兼容,并且除非確認新添加會引起阻塞問題,否則不需要任何特殊考慮。如果從版本19.3開始是這種情況,則可以禁用PropertyGrid滾動條主題。
如果從版本19.3開始是這種情況,則可以選擇禁用滾動條主題,以回退到19.2之前的行為。對于這個無論是取消對XTPPropertyGrid.h 文件中 (C:\Program Files (x86)\Codejock Software\MFC\Xtreme ToolkitPro v19.3.0\Source\PropertyGrid\XTPPropertyGrid.h) 的XTP_PROPERTY_GRID_DISABLE_SCROLLBAR_THEMES 宏或將宏定義為ToolkitPro或PropertyGrid庫項目的C ++編譯器屬性,然后重新構建ToolkitPro或PropertyGrid項目,以使更改生效。
使用這些類將確保控件將自動具有合適的滾動條主題,并可以使用新方法設置自定義滾動條主題:
void SetScrollBarTheme(XTPScrollBarTheme nTheme);
使用從CXTPScrollable派生的類同時也會施加某些限制:
CXTPTreeCtrl m_tree; // As CXTPTreeCtrl is derived from CTreeCtrl it uses CTreeCtrl::Create overloaded // method which has signature different from CWnd::Create and thus should not be used for CXTPScrollableTreeCtrl m_tree.Create(WS_CHILD | TVS_LINESATROOT, rc, this, IDC_TREE);
Example of the fixed code: CXTPScrollableTreeCtrl m_tree; // Call CWnd::Create overridden method to ensure it can be compiled using all Microsoft C++ compilers m_tree.Create(_T("SysTreeView32"), NULL, WS_CHILD | TVS_LINESATROOT, rc, this, IDC_TREE);
CXTPEdit m_edtSingleLine; CXTPScrollableEdit m_edtMultiline; // IDC_EDIT_SINGLELINE is NOT derived from CXTPScrollable and thus can be referenced by Resize control by ID only. SetResize(IDC_EDIT_SINGLELINE, XTP_ANCHOR_TOPLEFT, CXTPResizePoint(1.f / 3.f, 0)); // IDC_EDIT_MULTILINE is derived from CXTPScrollable and thus must be referenced by Resize control by both ID and handle value. SetResize(IDC_EDIT_MULTILINE, m_edtMultiline, XTP_ANCHOR_TOPLEFT, CXTPResizePoint(1.f / 3.f, 0));從CXTPScrollable派生自定義控件
如果控件來自于受支持的類并使用標準的Windows滾動條,則可以使用CXTPScrollable自定義控件來將其應用于滾動條。
有兩種可能的用例:
對于第一種情況,ToolkitPro為相應的基類提供了適配器模板:
例:
// Your existing classes class CCustomEdit : public CEdit { /*...*/ }; class CCustomTreeCtrl : public CXTPTreeCtrl { /*...*/ }; // Your new derived classes class CScrollableCustomEdit : public CXTPScrollableEditT<CCustomEdit> { /*...*/ }; class CScrollableTreeCtrl : public CXTPScrollableEditT<CCustomTreeCtrl> { /*...*/ };
在其他情況下,當您需要派生另一種自定義控件時,則需要實現 IXTPScrollable接口:
// Your existing class class CCustomControl : public CWnd { public: void InitializeCustomState(); // ... }; // Your new derived class. // Some or all method may have default implementation, the example demonstrates overloading of all methods. class CScrollableCustomControl : public CXTPScrollable { public: // IXTPScrollable overrides virtual BOOL HasVScroll(DWORD dwStyle, DWORD dwExStyle) const { // Determine if control has vertical scroll. return 0 != (GetStyle() & WS_VSCROLL); } virtual BOOL HasHScroll(DWORD dwStyle, DWORD dwExStyle) const { // Determine if control has horizontal scroll. return 0 != (GetStyle() & WS_HSCROLL); } virtual BOOL HasLeftScrollbar(DWORD dwStyle, DWORD dwExStyle) const { // Determine if control has scroll bar on the lets. return 0 != (GetExStyle() & WS_EX_LEFTSCROLLBAR); } virtual void DisableScrollbars() { // Force default scroll bars to hide. DisableScrollbars(*this); } virtual void DisableScrollbars(CWnd& wnd) { // Force default scroll bars to hide for a specific window. wnd.ModifyStyle(WS_VSCROLL | WS_HSCROLL, 0); } virtual CScrollBar* CreateBar() const { // Create scroll bar instance. return new CXTPScrollBarCtrl(); } virtual CWnd* CreateControl() const { // Re-create custom control instance and perform default initialization if necessary. CCustomControl* pNewCtrl = new CCustomControl(); VERIFY(NULL != pNewCtrl); pNewCtrl->InitializeCustomState(); return pNewCtrl; } virtual DWORD FilterStyle(DWORD dwStyle) const { return dwStyle; } virtual DWORD FilterExStyle(DWORD dwExStyle) const { return dwExStyle; } virtual BOOL RequiresMouseWheelOverriding() const { return true; } // ... };
今天的內容就是這些了,下載最新版Xtreme ToolKit Pro并在下方評論區分享您對該產品的想法。您的反饋意見可幫助我們在以后的更新中找到正確的方向,慧都作為Codejock的正版代理商現Xtreme ToolKit Pro正版授權最高立減2000元! Xtreme Command Bars在線訂購最低僅需1105元!
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自: