c++ - Disable annoying sound when handling syskeydown message -
hi have written own custom control overriding mfc cedit. needed override sys_key_up , sys_key_down. each time control handles these message annoying sound heard if input invalid or something. knwo generates sound , how disable it.
upd code
// cshotcutedit class cshortcutedit : public cedit { declare_dynamic(cshortcutedit) public: cshortcutedit(); virtual ~cshortcutedit(); protected: declare_message_map() afx_msg uint ongetdlgcode(); afx_msg void onkeydown(uint nchar, uint nrepcnt, uint nflags); afx_msg void onsyskeydown(uint nchar, uint nrepcnt, uint nflags); afx_msg void onsyskeyup(uint nchar, uint nrepcnt, uint nflags); afx_msg void onkeyup(uint nchar, uint nrepcnt, uint nflags); virtual bool pretranslatemessage(msg* pmsg); virtual void dodataexchange(cdataexchange* pdx); virtual void presubclasswindow(); virtual void onchar(uint uichar, uint uicount, uint uiflags); // ... other members }; // shotcutedit.cpp : implementation file // #include "stdafx.h" #include "gridplus.h" #include "shortcutedit.h" // cshotcutedit implement_dynamic(cshortcutedit, cedit) cshortcutedit::cshortcutedit() { } cshortcutedit::~cshortcutedit() { } begin_message_map(cshortcutedit, cedit) on_wm_getdlgcode() on_wm_keydown() on_wm_syskeydown() on_wm_syskeyup() on_wm_keyup() on_wm_char() end_message_map() uint cshortcutedit::ongetdlgcode() { return dlgc_wantarrows | dlgc_wantallkeys | dlgc_wantchars; } void cshortcutedit::dodataexchange(cdataexchange* pdx) { cedit::dodataexchange(pdx); } bool cshortcutedit::pretranslatemessage(msg* pmsg) { return cedit::pretranslatemessage(pmsg); } void cshortcutedit::onsyskeyup(uint nchar, uint nrepcnt, uint nflags) { } void cshortcutedit::onsyskeydown(uint nchar, uint nrepcnt, uint nflags) { // ... check alt or f10 , translate string; } void cshortcutedit::onkeydown(uint nchar, uint nrepcnt, uint nflags) { // .. check ctrl shift , translate string } void cshortcutedit::onkeyup(uint nchar, uint nrepcnt, uint nflags) { setwindowtext(l"the desired shortcut is..."); // should print "alt+f10" example } void cshortcutedit::onchar(uint uichar, uint uicount, uint uiflags) { } void cshortcutedit::presubclasswindow() { hidecaret(); cedit::presubclasswindow(); } // cshotcutedit message handlers
that's default behavior of edit control. notepad same thing in response alt+a key.
to avoid sound, overload pretranslatemessage
bool cshortcutedit::pretranslatemessage(msg* pmsg) { if (pmsg->message == wm_syskeydown) { uint nflags = hiword(pmsg->lparam); int nchar = (int)pmsg->wparam; if (nchar == 'a' && nflags & kf_altdown) { trace("alt+a key\n"); return 1; } } return cedit::pretranslatemessage(pmsg); }
also, if don't want edit control don't use one, rather using edit control , breaking every input.
you need chotkeyctrl
Comments
Post a Comment