Skip to content

Commit

Permalink
fix: Listen on WM_KEYDOWN instead of register for hotkey. Closes #14.
Browse files Browse the repository at this point in the history
  • Loading branch information
jixunmoe committed Oct 3, 2022
1 parent 379f8be commit 0b827c7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
33 changes: 14 additions & 19 deletions generator/AdvEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include "stdafx.h"
#include "AdvEdit.h"

#define SELECT_ALL_KEY_ID (10001)

// CAdvEdit

IMPLEMENT_DYNAMIC(CAdvEdit, CEdit)
Expand All @@ -32,26 +30,23 @@ void CAdvEdit::SelectAll()
SetSel(0, GetWindowTextLength(), FALSE);
}

void CAdvEdit::InitEvents()
{
RegisterHotKey(GetSafeHwnd(), SELECT_ALL_KEY_ID, MOD_CONTROL, 'A');
}

BEGIN_MESSAGE_MAP(CAdvEdit, CEdit)
ON_WM_HOTKEY()
ON_WM_KEYDOWN()
END_MESSAGE_MAP()



// CAdvEdit message handlers



void CAdvEdit::OnHotKey(UINT nHotKeyId, UINT nKey1, UINT nKey2)
void CAdvEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CEdit::OnHotKey(nHotKeyId, nKey1, nKey2);

if (nHotKeyId == SELECT_ALL_KEY_ID) {
this->SelectAll();
CEdit::OnKeyDown(nChar, nRepCnt, nFlags);

if (nChar == 'A') {
BYTE keyState[256] = { 0 };
GetKeyboardState(keyState);
bool useControl = (keyState[VK_CONTROL] & 0x80) != 0;
bool useShift = (keyState[VK_SHIFT] & 0x80) != 0;
bool useAlt = (keyState[VK_MENU] & 0x80) != 0;

if (useControl && !useShift && !useAlt) {
this->SelectAll();
}
}
}
3 changes: 1 addition & 2 deletions generator/AdvEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ class CAdvEdit : public CEdit
virtual ~CAdvEdit();
void Append(const CString &text);
void SelectAll();
void InitEvents();

protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnHotKey(UINT nHotKeyId, UINT nKey1, UINT nKey2);
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
};


1 change: 0 additions & 1 deletion generator/appDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ BOOL CAppDlg::OnInitDialog()
// 初始化目录选择
std::ignore = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);

m_editOutput.InitEvents();
m_editOutput.SetLimitText(0);


Expand Down
Binary file modified generator/generator.rc
Binary file not shown.

0 comments on commit 0b827c7

Please sign in to comment.