进度条
<p>进度条CProgress,继承于CView,支持CView的所有属性和方法。通过给进度条设置不同的背景图片资源,可以得到各种形态的进度条。</p>
<h2>属性和相关方法:</h2>
<h4>设置进度条的最大进度</h4>
<ul>
<li>通过XML属性控制如下:</li>
</ul>
<pre><code class="language-xml">Range="100"</code></pre>
<ul>
<li>通过C++程序代码调用方法控制如下:</li>
</ul>
<pre><code class="language-c">void SetRange(int64 nRange);</code></pre>
<h4>设置进度条的当前进度</h4>
<ul>
<li>通过XML属性控制如下:</li>
</ul>
<pre><code class="language-xml">Pos="1"</code></pre>
<ul>
<li>通过C++程序代码调用方法控制如下:</li>
</ul>
<pre><code class="language-c">void SetPos(int64 nPos);</code></pre>
<h2>示例</h2>
<h4>效果图</h4>
<p><img src="http://www.skinui.cn/doc/img/5.0/3/Progress.png" alt="进度条" /></p>
<h4>布局文件</h4>
<pre><code class="language-xml"><FlexLayout>
<TextView Width="MatchParent" Height="60" HorzAlign="Center" Text="IDS_CONTROL11_2" Font="ID_FONT_H4"/>
<Line Width="MatchParent" Height="1" Margin="0,0,0,20"/>
<RelativeLayout Width="MatchParent" Height="160">
<Progress Id="101" Height="9" AlignParentLeft="40" AlignParentRight="40" AlignParentTop="20" Range="100" Pos="0" Background="Progress.png"/>
<Button Id="201" Width="WrapContent" Height="30" ChildText11="增加进度, Step=4" Background="Button.png" Layout="Button.xml" AlignParentHorzCenter="0" ToBottomOf="101,10"/>
<Progress Id="102" Height="9" AlignParentLeft="40" AlignParentRight="40" ToBottomOf="201,30" Range="100" Pos="0" Background="Progress2.png"/>
<Button Id="202" Width="WrapContent" Height="30" ChildText11="增加进度, Step=10" Background="Button.png" Layout="Button.xml" AlignParentHorzCenter="0" ToBottomOf="102,10"/>
</RelativeLayout>
</FlexLayout></code></pre>
<h4>h文件</h4>
<pre><code class="language-cpp">#pragma once
class CDemoProgressLayout : public CScrollLayout
{
public:
enum
{
IDC_PROGRESS1 = 101,
IDC_BUTTON1 = 201,
IDC_PROGRESS2 = 102,
IDC_BUTTON2 = 202,
};
public:
CDemoProgressLayout(CView* pParent);
public:
virtual void OnBuildFinish();
protected:
void OnBtnClickedAddPosByStep4(UINT uNotifyCode, int nID, CView* pView);
void OnBtnClickedAddPosByStep10(UINT uNotifyCode, int nID, CView* pView);
SKINUI_DECLARE_MESSAGE_MAP()
private:
CProgress* m_pProgress1;
CProgress* m_pProgress2;
SKINUI_DECLARE_DYNCREATE(CDemoProgressLayout, CScrollLayout)
};</code></pre>
<h4>cpp文件</h4>
<pre><code class="language-cpp">#include <stdafx.h>
#include "DemoProgressLayout.h"
SKINUI_BEGIN_MESSAGE_MAP(CDemoProgressLayout, CScrollLayout)
ON_SKINUI_COMMAND(IDC_BUTTON1, OnBtnClickedAddPosByStep4)
ON_SKINUI_COMMAND(IDC_BUTTON2, OnBtnClickedAddPosByStep10)
SKINUI_END_MESSAGE_MAP()
CDemoProgressLayout::CDemoProgressLayout(CView* pParent)
: CScrollLayout(pParent)
, m_pProgress1(NULL)
, m_pProgress2(NULL)
{
}
void CDemoProgressLayout::OnBuildFinish()
{
CScrollLayout::OnBuildFinish();
m_pProgress1 = dynamic_cast<CProgress*>(GetChildById(IDC_PROGRESS1));
m_pProgress2 = dynamic_cast<CProgress*>(GetChildById(IDC_PROGRESS2));
}
void CDemoProgressLayout::OnBtnClickedAddPosByStep4(UINT uNotifyCode, int nID, CView* pView)
{
if(m_pProgress1)
{
m_pProgress1->SetPos(min(m_pProgress1->GetPos() + 4, m_pProgress1->GetRange()));
m_pProgress1->Redraw();
}
}
void CDemoProgressLayout::OnBtnClickedAddPosByStep10(UINT uNotifyCode, int nID, CView* pView)
{
if(m_pProgress2)
{
m_pProgress2->SetPos(min(m_pProgress2->GetPos() + 10, m_pProgress2->GetRange()));
m_pProgress2->Redraw();
}
}</code></pre>