SkinUI5.0官方文档

SkinUI5.0官方文档


按钮

<p>按钮CButton,继承于CView,支持CView的所有属性和方法。通过给按钮设置不同的布局文件,可以得到各种形态的按钮。</p> <h2>1 属性和相关方法</h2> <h4>1.1 显示加载中</h4> <ul> <li>通过C++程序代码调用方法控制如下:</li> </ul> <pre><code class="language-c">void ShowLoading(BOOL bLoading);</code></pre> <h2>2 消息处理</h2> <h4>2.1 WM_COMMAND消息</h4> <p>单击按钮,鼠标左键抬起时:</p> <ul> <li>如果按钮Id不为0,会给所在的窗口发送WM_COMMAND消息。</li> <li>如果按钮存在菜单属性,会弹出对应的菜单。</li> </ul> <p>请参考下面的代码:</p> <pre><code class="language-cpp">void CButton::HandleLButtonUp(CPoint point, BOOL&amp; bHandle) { if(m_pViewLoading) { return; } if(GetState() == PRESSED) { if(GetId() != 0) { GetOwner()-&gt;PostMessage(WM_COMMAND, GetId(), reinterpret_cast&lt;LPARAM&gt;(this)); } if(!GetMenu().empty()) { CRect rect = GetRect(); CPoint ptPopup(rect.left, rect.bottom); ptPopup -= GetScrollOffset(); GetOwner()-&gt;ClientToScreen(ptPopup); GetOwner()-&gt;PopupMenu(GetMenu(), ptPopup, rect.Size(), this); } SetState(HOVER); Redraw(); } CFlexLayout::HandleLButtonUp(point, bHandle); }</code></pre> <h2>请看下面的示例</h2> <h4>效果图</h4> <p><img src="http://www.skinui.cn/doc/img/5.0/3/Button.png" alt="按钮" /></p> <h4>布局文件</h4> <ul> <li>普通按钮</li> </ul> <pre><code class="language-xml">&lt;Button Id="1000" Width="WrapContent" Height="WrapContent" AlignParentLeft="0" AlignParentVertCenter="0" Background="Button.png" Layout="Button.xml" ChildText11="IDS_CANCEL"/&gt; &lt;Button Id="1001" Width="WrapContent" Height="WrapContent" ToRightOf="1000,20" AlignParentVertCenter="0" Background="Button2.png" Layout="Button.xml" ChildText11="IDS_OK" ChildColor11="ID_COLOR_WHITE"/&gt; &lt;Button Id="1002" Width="WrapContent" Height="WrapContent" ToRightOf="1001,20" AlignParentVertCenter="0" Background="Button.png" Layout="Button.xml" ChildText11="IDS_DELETE" ChildColor11="ID_COLOR_RED"/&gt; &lt;Button Id="1003" Width="WrapContent" Height="WrapContent" ToRightOf="1002,20" AlignParentVertCenter="0" Background="Button3.png" Layout="Button.xml" ChildText11="IDS_ADD"/&gt;</code></pre> <ul> <li>位图按钮</li> </ul> <pre><code class="language-xml">&lt;Button Id="1000" Width="WrapContent" Height="WrapContent" AlignParentLeft="0" AlignParentVertCenter="0" Background="BitmapButton.png"/&gt;</code></pre> <ul> <li>图标按钮</li> </ul> <pre><code class="language-xml">&lt;Button Id="1000" Width="WrapContent" Height="WrapContent" AlignParentLeft="0" AlignParentVertCenter="0" Background="Button.png" Layout="IconButton.xml" ChildImage10="Icon.png"/&gt; &lt;Button Id="1001" Width="WrapContent" Height="WrapContent" ToRightOf="1000,20" AlignParentVertCenter="0" Background="Button2.png" Layout="IconButton.xml" ChildImage10="Icon.png"/&gt; &lt;Button Id="1002" Width="WrapContent" Height="WrapContent" ToRightOf="1001,20" AlignParentVertCenter="0" Background="Button3.png" Layout="IconButton.xml" ChildImage10="Icon.png"/&gt;</code></pre> <ul> <li>图标按钮带文字</li> </ul> <pre><code class="language-xml">&lt;Button Id="1000" Width="WrapContent" Height="WrapContent" AlignParentLeft="0" AlignParentVertCenter="0" Background="Button.png" Layout="IconButtonWithText.xml" ChildImage10="Icon.png" ChildText11="IDS_CANCEL"/&gt; &lt;Button Id="1001" Width="WrapContent" Height="WrapContent" ToRightOf="1000,20" AlignParentVertCenter="0" Background="Button2.png" Layout="IconButtonWithText.xml" ChildImage10="Icon.png" ChildText11="IDS_OK" ChildColor11="ID_COLOR_WHITE"/&gt; &lt;Button Id="1002" Width="WrapContent" Height="WrapContent" ToRightOf="1001,20" AlignParentVertCenter="0" Background="Button.png" Layout="IconButtonWithText.xml" ChildImage10="Icon.png" ChildText11="IDS_DELETE" ChildColor11="ID_COLOR_RED"/&gt; &lt;Button Id="1003" Width="WrapContent" Height="WrapContent" ToRightOf="1002,20" AlignParentVertCenter="0" Background="Button3.png" Layout="IconButtonWithText.xml" ChildImage10="Icon.png" ChildText11="IDS_ADD"/&gt;</code></pre> <h4>h文件</h4> <pre><code class="language-c">#pragma once class CDemoButtonLayout : public CScrollLayout { public: enum { IDC_BUTTON1 = 1000, IDC_BUTTON4 = 1003, }; public: CDemoButtonLayout(CView* pParent); public: virtual void OnBuildFinish(); virtual void OnTimer(UINT_PTR nIDEvent); protected: void OnButtonClicked(UINT uNotifyCode, int nID, CView* pView); SKINUI_DECLARE_MESSAGE_MAP() private: CButton* m_pButton; SKINUI_DECLARE_DYNCREATE(CDemoButtonLayout, CScrollLayout) };</code></pre> <h4>cpp文件</h4> <pre><code class="language-c">#include &lt;stdafx.h&gt; #include "DemoButtonLayout.h" SKINUI_BEGIN_MESSAGE_MAP(CDemoButtonLayout, CScrollLayout) ON_SKINUI_COMMAND_RANGE(IDC_BUTTON1, IDC_BUTTON4, OnButtonClicked) SKINUI_END_MESSAGE_MAP() CDemoButtonLayout::CDemoButtonLayout(CView* pParent) : CScrollLayout(pParent) , m_pButton(NULL) { } void CDemoButtonLayout::OnBuildFinish() { CScrollLayout::OnBuildFinish(); } void CDemoButtonLayout::OnTimer(UINT_PTR nIDEvent) { KillTimer(nIDEvent); if(m_pButton) { m_pButton-&gt;ShowLoading(FALSE); m_pButton = NULL; } } void CDemoButtonLayout::OnButtonClicked(UINT uNotifyCode, int nID, CView* pView) { if(m_pButton) { m_pButton-&gt;ShowLoading(FALSE); } m_pButton = dynamic_cast&lt;CButton*&gt;(pView); if(m_pButton) { m_pButton-&gt;ShowLoading(TRUE); SetTimer(0, 5000); } }</code></pre>

页面列表

ITEM_HTML