单选框
<p>超链CRadioButton,继承于CButton,支持CButton的所有属性和方法。</p>
<h2>属性和相关方法</h2>
<h4>设置单选框是否选中</h4>
<ul>
<li>通过XML属性控制如下:</li>
</ul>
<pre><code class="language-xml">Checked="true"</code></pre>
<ul>
<li>通过C++程序代码调用方法控制如下:</li>
</ul>
<pre><code class="language-c">virtual void SetChecked(BOOL bChecked);</code></pre>
<h4>设置单选框绑定的视图</h4>
<ul>
<li>通过XML属性控制如下:</li>
</ul>
<pre><code class="language-xml">BindView="1001"</code></pre>
<ul>
<li>通过C++程序代码调用方法控制如下:</li>
</ul>
<pre><code class="language-c">void SetBindView(LONG nBindView);</code></pre>
<h2>消息处理</h2>
<h4>WM_RADIO_GROUP_CHECKED_CHANGE</h4>
<p>单选框一般作为CRadioGroup的子控件,这样可以用来做互斥的选择。当CRadioGroup的选中状态发生变化时,会切换绑定的视图,同时会给所在窗口发送自定义消息WM_RADIO_GROUP_CHECKED_CHANGE。</p>
<ul>
<li>参考下面的示例代码:</li>
</ul>
<pre><code class="language-cpp">void CRadioGroup::SetChecked(CRadioButton* pRadioButton)
{
CRadioButton* pOldChecked = GetChecked();
CRadioButton* pNewChecked = pRadioButton;
if(pOldChecked == pNewChecked)
{
return;
}
CRedrawLocker locker(GetOwner());
if(pNewChecked)
{
pNewChecked->SetChecked(TRUE);
}
if(pOldChecked)
{
pOldChecked->SetChecked(FALSE);
if(pOldChecked->IsVisible())
{
pOldChecked->SetState(NORMAL);
}
}
CView* pBindView = GetBindView(pNewChecked);
if(pBindView)
{
CSwitchLayout* pAnimationView = dynamic_cast<CSwitchLayout*>(pBindView->GetParent());
if(pAnimationView)
{
pAnimationView->Show(pBindView);
}
else
{
pBindView->SetState(NORMAL);
CView* pBindView = GetBindView(pOldChecked);
if(pBindView)
{
pBindView->SetState(HIDED);
}
}
}
GetOwner()->SendMessage(WM_RADIO_GROUP_CHECKED_CHANGE, GetId(), reinterpret_cast<LPARAM>(this));
}</code></pre>
<ul>
<li>消息处理示例:</li>
</ul>
<pre><code class="language-cpp">void OnRadioGroupCheckedChange(LONG nId, CRadioGroup* pRadioGroup, BOOL& bHandle);
SKINUI_DECLARE_MESSAGE_MAP()</code></pre>
<pre><code class="language-cpp">SKINUI_BEGIN_MESSAGE_MAP(CDemoRadioButtonLayout, CScrollLayout)
ON_SKINUI_WM_RADIO_GROUP_CHECKED_CHANGE()
SKINUI_END_MESSAGE_MAP()
void CDemoRadioButtonLayout::OnRadioGroupCheckedChange(LONG nId, CRadioGroup* pRadioGroup, BOOL& bHandle)
{
bHandle = TRUE;
}</code></pre>
<h4>WM_RADIO_BUTTON_CHECKED_CHANGE</h4>
<p>单选框选中状态发生变化时,会给所在窗口发送自定义消息WM_RADIO_BUTTON_CHECKED_CHANGE。</p>
<ul>
<li>参考下面的示例代码:</li>
</ul>
<pre><code class="language-cpp">void CRadioButton::SetChecked(BOOL bChecked)
{
BOOL bOldChecked = IsChecked();
if(bOldChecked != bChecked)
{
CButton::SetChecked(bChecked);
GetOwner()->SendMessage(WM_RADIO_BUTTON_CHECKED_CHANGE, GetId(), reinterpret_cast<LPARAM>(this));
}
}</code></pre>
<ul>
<li>消息处理示例:</li>
</ul>
<pre><code class="language-cpp">void OnRadioButtonCheckedChange(LONG nId, CRadioButton* pRadioButton, BOOL& bHandle);
SKINUI_DECLARE_MESSAGE_MAP()</code></pre>
<pre><code class="language-cpp">SKINUI_BEGIN_MESSAGE_MAP(CDemoRadioButtonLayout, CScrollLayout)
ON_SKINUI_WM_RADIO_BUTTON_CHECKED_CHANGE()
SKINUI_END_MESSAGE_MAP()
void CDemoRadioButtonLayout::OnRadioButtonCheckedChange(LONG nId, CRadioButton* pRadioButton, BOOL& bHandle)
{
bHandle = TRUE;
}</code></pre>
<h2>示例</h2>
<h4>效果图</h4>
<p><img src="http://www.skinui.cn/doc/img/5.0/3/RadioButton.png" alt="超链" /></p>
<h4>普通单选框</h4>
<pre><code class="language-xml"><RadioButton Id="1000" Width="WrapContent" Height="WrapContent" Layout="RadioButton.xml" ChildText11="普通单选框"/>
<RadioButton Id="1001" Width="WrapContent" Height="WrapContent" Layout="RadioButton.xml" ChildText11="普通单选框" Checked="true"/></code></pre>
<h4>单选框不带文字</h4>
<pre><code class="language-xml"><RadioButton Id="1000" Width="WrapContent" Height="WrapContent" Layout="RadioButton.xml"/>
<RadioButton Id="1001" Width="WrapContent" Height="WrapContent" Layout="RadioButton.xml" Checked="true"/></code></pre>
<h4>单选框带图标</h4>
<pre><code class="language-xml"><RadioButton Id="1000" Width="WrapContent" Height="WrapContent" Layout="RadioButtonWithIcon.xml" ChildImage11="Icon.png" ChildText12="单选框带图标"/>
<RadioButton Id="1001" Width="WrapContent" Height="WrapContent" Layout="RadioButtonWithIcon.xml" ChildImage11="Icon.png" ChildText12="单选框带图标" Checked="true"/></code></pre>
<h4>单选框带图标不带文字</h4>
<pre><code class="language-xml"><RadioButton Id="1000" Width="WrapContent" Height="WrapContent" Layout="RadioButtonWithIcon.xml" ChildImage11="Icon.png"/>
<RadioButton Id="1001" Width="WrapContent" Height="WrapContent" Layout="RadioButtonWithIcon.xml" ChildImage11="Icon.png" Checked="true"/></code></pre>