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; strMenu, const CPoint&amp; ptPopup, const CSize&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; xmlNode, const CPoint&amp; ptPopup, const CSize&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-&gt;GetRect();
CPoint ptOffset = pView-&gt;GetScrollOffset(CRect());
CPoint pt(rect.left - ptOffset.x, rect.bottom - ptOffset.y);
pView-&gt;GetOwner()-&gt;ClientToScreen(pt);
SkinUI::PopupMenu(this, _T(&quot;MainMenu.xml&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 &quot;stdafx.h&quot;
#include &quot;MainDialog.h&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-&gt;SetEnable(FALSE);
pView-&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 &quot;stdafx.h&quot;
#include &quot;MainDialog.h&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(&quot;http://www.skinui.cn&quot;);
::ShellExecute(m_hWnd, _T(&quot;open&quot;), strUrl.c_str(), NULL, NULL, SW_SHOWNORMAL);
}</code></pre>