SkinUI入门教程

SkinUI入门教程


4.1 菜单

<p>菜单是Windows客户端最常用的组件之一 <img src="http://www.skinui.cn/doc/img/4/1/1.png" alt="菜单" /></p> <h2>1 弹出菜单</h2> <ul> <li>调用以下接口弹出资源菜单:</li> </ul> <pre><code class="language-c">HWND CSkinDialog::PopupMenu(const tstring&amp;amp; strMenu, const CPoint&amp;amp; ptPopup, const CSize&amp;amp; szButton, PopupDirection direction = PD_UNKNOWN, CSkinView* pNotifyView = NULL);</code></pre> <ul> <li>调用以下接口弹出动态菜单:</li> </ul> <pre><code class="language-c">HWND CSkinDialog::PopupMenu(const CXMLNode&amp;amp; xmlNode, const CPoint&amp;amp; ptPopup, const CSize&amp;amp; szButton, PopupDirection direction = PD_UNKNOWN, CSkinView* pNotifyView = NULL);</code></pre> <p>弹出菜单时,可以自适应方向弹出,也可以指定弹出方向。</p> <pre><code class="language-c">//弹出方向 enum PopupDirection { PD_UNKNOWN = 0x0000, //自适应 PD_LEFT_TOP = 0x0001, //左上弹出 PD_RIGHT_TOP = 0x0002, //右上弹出 PD_LEFT_BOTTOM = 0x0004, //左下弹出 PD_RIGHT_BOTTOM = 0x0008 //右下弹出 };</code></pre> <ul> <li>下面是弹出菜单的代码的示例代码:</li> </ul> <pre><code class="language-c">void CMainDialog::OnBtnClickedPopMenu(UINT uNotifyCode, int nID, CSkinView* pView) { if(pView) { CRect rect = pView-&amp;gt;GetRect(); CPoint ptOffset = pView-&amp;gt;GetScrollOffset(CRect()); CPoint pt(rect.left - ptOffset.x, rect.bottom - ptOffset.y); pView-&amp;gt;GetOwner()-&amp;gt;ClientToScreen(pt); SkinUI::PopupMenu(this, _T(&amp;quot;MainMenu.xml&amp;quot;), pt,rect.Size(), PD_UNKNOWN); } }</code></pre> <h2>2 响应菜单更新消息</h2> <h4>h文件</h4> <pre><code class="language-c">protected: void OnUpdateCommandOfficialWebsite(CSkinView* pView); SKINUI_DECLARE_MESSAGE_MAP()</code></pre> <h4>cpp文件</h4> <pre><code class="language-c">#include &amp;quot;stdafx.h&amp;quot; #include &amp;quot;MainDialog.h&amp;quot; SKINUI_BEGIN_MESSAGE_MAP(CMainDialog, CSkinDialog) ON_SKINUI_UPDATE_COMMAND_UI(MENU_OFFICIAL_WEBSITE, OnUpdateCommandOfficialWebsite) SKINUI_END_MESSAGE_MAP() void CMainDialog::OnUpdateCommandOfficialWebsite(CSkinView* pView) { pView-&amp;gt;SetEnable(FALSE); pView-&amp;gt;SetVisible(FALSE); }</code></pre> <h2>3 响应菜单命令消息</h2> <h4>h文件</h4> <pre><code class="language-c">protected: void OnMenuCommandOfficialWebsite(UINT uNotifyCode, int nID, CSkinView* pView); SKINUI_DECLARE_MESSAGE_MAP()</code></pre> <h4>cpp文件</h4> <pre><code class="language-c">#include &amp;quot;stdafx.h&amp;quot; #include &amp;quot;MainDialog.h&amp;quot; SKINUI_BEGIN_MESSAGE_MAP(CMainDialog, CSkinDialog) ON_SKINUI_COMMAND(MENU_OFFICIAL_WEBSITE, OnMenuCommandOfficialWebsite) SKINUI_END_MESSAGE_MAP() void CMainDialog::OnMenuCommandOfficialWebsite(UINT uNotifyCode, int nID, CSkinView* pView) { tstring strUrl = _T(&amp;quot;http://www.skinui.cn&amp;quot;); ::ShellExecute(m_hWnd, _T(&amp;quot;open&amp;quot;), strUrl.c_str(), NULL, NULL, SW_SHOWNORMAL); }</code></pre>

页面列表

ITEM_HTML