76 lines
1.9 KiB
C++
76 lines
1.9 KiB
C++
#include "stdafx.h"
|
|
#include "CmdQueryHotkeyDlg.h"
|
|
#include "CmdQuery.h"
|
|
|
|
IMPLEMENT_DYNAMIC(CmdQueryHotkeyDlg, CDialog)
|
|
|
|
CmdQueryHotkeyDlg::CmdQueryHotkeyDlg(CWnd* pParent /*=nullptr*/)
|
|
: CDialog(IDD_CMDS_HOTKEY, pParent) { }
|
|
|
|
CmdQueryHotkeyDlg::~CmdQueryHotkeyDlg() { }
|
|
|
|
void CmdQueryHotkeyDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_EDT, m_edtHotkey);
|
|
}
|
|
|
|
BOOL CmdQueryHotkeyDlg::OnInitDialog()
|
|
{
|
|
CString str = CmdQuery::getHotkeyString();
|
|
SetWindowText(CString(_T("上华命令搜索 ")) + str);
|
|
return CDialog::OnInitDialog();
|
|
}
|
|
|
|
BOOL CmdQueryHotkeyDlg::PreTranslateMessage(MSG * pMsg)
|
|
{
|
|
if (pMsg->message == WM_KEYDOWN)
|
|
{
|
|
WPARAM wp = pMsg->wParam;
|
|
if (wp == VK_RETURN) return FALSE;
|
|
if (wp == VK_ESCAPE) return FALSE;
|
|
if (wp == VK_LWIN) return FALSE;
|
|
if (wp == VK_RWIN) return FALSE;
|
|
if (wp == VK_TAB) return FALSE;
|
|
if (wp == VK_CAPITAL) return FALSE;
|
|
if (wp == VK_BACK)
|
|
{
|
|
m_chs.clear();
|
|
}
|
|
else
|
|
{
|
|
CString ch = CmdQuery::getCharByKey(wp);
|
|
m_chs[wp] = ch;
|
|
}
|
|
|
|
if (CmdQuery::checkHotkey(m_chs))
|
|
{
|
|
std::map<WPARAM, CString>::const_iterator it = m_chs.begin();
|
|
std::wstringstream ws;
|
|
for (; it != m_chs.end(); ++it)
|
|
ws << (LPCTSTR)it->second << _T(" + ");
|
|
m_edtHotkey.SetWindowText(ws.str().substr(0, ws.str().size() - 3).c_str());
|
|
}
|
|
return TRUE;
|
|
}
|
|
return CDialog::PreTranslateMessage(pMsg);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CmdQueryHotkeyDlg, CDialog)
|
|
ON_BN_CLICKED(IDOK, &CmdQueryHotkeyDlg::OnBnClickedOk)
|
|
END_MESSAGE_MAP()
|
|
|
|
void CmdQueryHotkeyDlg::OnBnClickedOk()
|
|
{
|
|
if (CmdQuery::checkHotkey(m_chs))
|
|
{
|
|
CmdQuery::saveHotKey(m_chs);
|
|
CWnd *pParent = GetParent();
|
|
if (pParent)
|
|
pParent->SetWindowText(CString("上华命令搜索 ") + CmdQuery::getHotkeyString());
|
|
}
|
|
else
|
|
AfxMessageBox(_T("输入的热键不符合条件!\n请至少按下ctrl,shift,alt三个键中的一个,再按下其它按键至少一个."));
|
|
CDialog::OnOK();
|
|
}
|