解决Duilib中的Combo下拉框滚动条不显示问题

274 阅读1分钟

1.在Default属性里面要添加滚动条的资源

<Default name="VScrollBar" value="button1normalimage=&quot;file='scrollbar.png' source='0,90,16,106' mask='#FFFF00FF'&quot; button1hotimage=&quot;file='scrollbar.png' source='18,90,34,106' mask='#FFFF00FF'&quot; button1pushedimage=&quot;file='scrollbar.png' source='36,90,52,106' mask='#FFFF00FF'&quot; button1disabledimage=&quot;file='scrollbar.png' source='54,90,70,106' mask='#FFFF00FF'&quot; button2normalimage=&quot;file='scrollbar.png' source='0,108,16,124' mask='#FFFF00FF'&quot; button2hotimage=&quot;file='scrollbar.png' source='18,108,34,124' mask='#FFFF00FF'&quot; button2pushedimage=&quot;file='scrollbar.png' source='36,108,52,124' mask='#FFFF00FF'&quot; button2disabledimage=&quot;file='scrollbar.png' source='54,108,70,124' mask='#FFFF00FF'&quot; thumbnormalimage=&quot;file='scrollbar.png' source='0,126,16,142' corner='2,2,2,2' mask='#FFFF00FF'&quot; thumbhotimage=&quot;file='scrollbar.png' source='18,126,34,142' corner='2,2,2,2' mask='#FFFF00FF'&quot; thumbpushedimage=&quot;file='scrollbar.png' source='36,126,52,142' corner='2,2,2,2' mask='#FFFF00FF'&quot; thumbdisabledimage=&quot;file='scrollbar.png' source='54,126,70,142' corner='2,2,2,2' mask='#FFFF00FF'&quot; railnormalimage=&quot;file='scrollbar.png' source='0,144,16,160' corner='2,2,2,2' mask='#FFFF00FF'&quot; railhotimage=&quot;file='scrollbar.png' source='18,144,34,160' corner='2,2,2,2' mask='#FFFF00FF'&quot; railpushedimage=&quot;file='scrollbar.png' source='36,144,52,160' corner='2,2,2,2' mask='#FFFF00FF'&quot; raildisabledimage=&quot;file='scrollbar.png' source='54,144,70,160' corner='2,2,2,2' mask='#FFFF00FF'&quot; bknormalimage=&quot;file='scrollbar.png' source='0,162,16,178' corner='2,2,2,2' mask='#FFFF00FF'&quot; bkhotimage=&quot;file='scrollbar.png' source='18,162,34,178' corner='2,2,2,2' mask='#FFFF00FF'&quot; bkpushedimage=&quot;file='scrollbar.png' source='36,162,52,178' corner='2,2,2,2' mask='#FFFF00FF'&quot; bkdisabledimage=&quot;file='scrollbar.png' source='54,162,70,178' corner='2,2,2,2' mask='#FFFF00FF'&quot; " />

2.修改Duilib的源码,在代码里面把资源加载进去

LRESULT CComboWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    if( uMsg == WM_CREATE ) {
		m_pm.SetForceUseSharedRes(true);
        m_pm.Init(m_hWnd);
        // The trick is to add the items to the new container. Their owner gets
        // reassigned by this operation - which is why it is important to reassign
        // the items back to the righfull owner/manager when the window closes.
        m_pLayout = new CComboBodyUI(m_pOwner);
        m_pLayout->SetManager(&m_pm, NULL, true);
        LPCTSTR pDefaultAttributes = m_pOwner->GetManager()->GetDefaultAttributeList(_T("VerticalLayout"));
        if( pDefaultAttributes ) {
            m_pLayout->SetAttributeList(pDefaultAttributes);
        }

		pDefaultAttributes = m_pOwner->GetManager()->GetDefaultAttributeList(_T("HScrollBar"));
		if (pDefaultAttributes) {
			m_pm.AddDefaultAttributeList(_T("HScrollBar"), pDefaultAttributes);
		}
		pDefaultAttributes = m_pOwner->GetManager()->GetDefaultAttributeList(_T("VScrollBar"));
		if (pDefaultAttributes) {
			m_pm.AddDefaultAttributeList(_T("VScrollBar"), pDefaultAttributes);
		}

AddDefaultAttributeList为加载默认资源属性

3.在Default里面要设置

shared="true"

4.在Combo属性里添加滚动条属性

<Combo name="cpucombo" vscrollbar="true" hscrollBar="true" float="true" pos="170,0,0,0" width="192" height="28" itemtextpadding="8,0,0,0" itemtextcolor="#FFb5b4b4" itemselectedtextcolor="#FFFFFFFF"  itemhottextcolor="#FFFFFFFF" itemdisabledtextcolor="#FFCCCCCC" itemdisabledbkcolor="#FFFFFFFF" itembkimage="file=&apos;combo_itemback.png&apos; source=&apos;0,0,24,24&apos; corner=&apos;4,4,4,4&apos;" itemselectedimage="file=&apos;combo_itemback.png&apos; source=&apos;24,0,48,24&apos; corner=&apos;4,4,4,4&apos;" itemhotimage="file=&apos;combo_itemback.png&apos; source=&apos;24,0,48,24&apos; corner=&apos;4,4,4,4&apos;" normalimage="file=&apos;combo_background.png&apos; source=&apos;0,0,34,28&apos; corner=&apos;4,4,29,4&apos;" hotimage="file=&apos;combo_background.png&apos; source=&apos;34,0,68,28&apos; corner=&apos;4,4,29,4&apos;" pushedimage="file=&apos;combo_background.png&apos; source=&apos;68,0,102,28&apos; corner=&apos;4,4,29,4&apos;" disabledimage="file=&apos;combo_background.png&apos; source=&apos;102,0,136,28&apos; corner=&apos;4,4,29,4&apos;" dropboxsize="0,140" >
                            	<ListLabelElement text="Auto" />
                            	<ListLabelElement text="1 cores" />
                            	<ListLabelElement text="2 cores" />
                            	<ListLabelElement text="3 cores" />
                            	<ListLabelElement text="4 cores" />
                            </Combo>

深圳程序员交流群550846167