热键选择框
<p>热键选择框CHotKeyView,继承于CEditView,支持CEditView的所有属性和方法。</p>
<h2>消息处理</h2>
<h4>WM_HOTKEY_CHANGE</h4>
<p>热键列表框的值发生变化时,会给所在窗口发送自定义消息WM_HOTKEY_CHANGE。</p>
<p>参考下面的示例代码:</p>
<pre><code class="language-cpp">void CHotKeyView::HandleKeyDown(TCHAR vkey, UINT repeats, UINT code, BOOL& bHandle)
{
String strVirtualKeyCode = CStringHelper::VirtualKeyCodeToString(vkey);
if(!strVirtualKeyCode.empty())
{
m_bKeyUpClear = FALSE;
m_wVirtualKeyCode = vkey;
m_wModifiers = CMiscHelper::GetCurModifiers();
if(m_wModifiers == 0 && CMiscHelper::NeedDefaultModifiers(vkey))
{
m_wModifiers = 3;
}
SetText(CStringHelper::ModifiersToString(m_wModifiers) + strVirtualKeyCode);
GetOwner()->SendMessage(WM_HOTKEY_CHANGE, GetId(), reinterpret_cast<LPARAM>(this));
}
else
{
m_wModifiers = 0;
m_wVirtualKeyCode = 0;
m_bKeyUpClear = TRUE;
if(vkey == VK_SHIFT || vkey == VK_CONTROL || vkey == VK_MENU)
{
WORD wModifiers = CMiscHelper::GetCurModifiers();
String strModifiers = CStringHelper::ModifiersToString(wModifiers);
SetText(strModifiers);
}
else if(vkey == VK_BACK || vkey == VK_DELETE || vkey == VK_RETURN)
{
SetText(String());
}
}
bHandle = TRUE;
}</code></pre>
<h2>请看下面的示例</h2>
<h4>效果图</h4>
<p><img src="http://www.skinui.cn/doc/img/5.0/3/ComboBox.png" alt="下拉列表框" /></p>
<pre><code class="language-xml"><RelativeLayout AlignParentLeft="40" AlignParentTop="0" AlignParentRight="20" AlignParentBottom="0">
<HotKeyView Id="1001" Width="200" Height="30" Background="Edit.png" AlignParentLeft="0" AlignParentVertCenter="0"/>
</RelativeLayout></code></pre>
<h4>h文件</h4>
<pre><code class="language-cpp">#pragma once
class CDemoHotKeyViewLayout : public CScrollLayout
{
public:
enum
{
IDC_HOTKEY = 1001,
};
public:
CDemoHotKeyViewLayout(CView* pParent);
public:
virtual void OnBuildFinish();
protected:
void OnHotKeyChange(LONG nId, CHotKeyView* pHotKeyView, BOOL& bHandle);
SKINUI_DECLARE_MESSAGE_MAP()
SKINUI_DECLARE_DYNCREATE(CDemoHotKeyViewLayout, CScrollLayout)
};</code></pre>
<h4>cpp文件</h4>
<pre><code class="language-cpp">#include <stdafx.h>
#include "DemoHotKeyViewLayout.h"
SKINUI_BEGIN_MESSAGE_MAP(CDemoHotKeyViewLayout, CScrollLayout)
ON_SKINUI_WM_HOTKEY_CHANGE()
SKINUI_END_MESSAGE_MAP()
CDemoHotKeyViewLayout::CDemoHotKeyViewLayout(CView* pParent)
: CScrollLayout(pParent)
{
}
void CDemoHotKeyViewLayout::OnBuildFinish()
{
CScrollLayout::OnBuildFinish();
CHotKeyView* pHotKeyView = dynamic_cast<CHotKeyView*>(GetChildById(IDC_HOTKEY));
if(pHotKeyView)
{
pHotKeyView->SetHotKey(HOTKEYF_CONTROL | HOTKEYF_SHIFT, VK_DOWN);
}
}
void CDemoHotKeyViewLayout::OnHotKeyChange(LONG nId, CHotKeyView* pHotKeyView, BOOL& bHandle)
{
bHandle = TRUE;
GetOwner()->Toast(_T("HotKey Change To: ") + pHotKeyView->GetText());
}</code></pre>