Recently writeProgramThe background thread needs to display a progress window for execution, and this window does not need to be closed by the user, so I want to block the Alt + F4 and escape messages.
In general, you can think of processing wm_keydown and wm_syskeydown messages immediately:
Afx_msg void onkeydown (uint nchar, uint nrepcnt, uint nflags); afx_msg void onsyskeydown (uint nchar, uint nrepcnt, uint nflags );
This is correct, but the class derived from cdialog does not respond to the two messages, so you have to find another way to start with pretranslatemessage:
Virtual bool pretranslatemessage (MSG * PMSG); // by David Hsing: http://blog.csdn.net/DavidHsing/BOOL cxxxdialog: pretranslatemessage (MSG * PMSG) {If (PMSG-> message = wm_keydown & PMSG-> wparam = vk_escape) | (PMSG-> message = wm_syskeydown & PMSG-> wparam = vk_f4) {# ifdef _ debug trace0 ("cxxxdialog. pretranslatemessage (): ESC or Alt + F4 key is pressed. ignored. \ n "); # endif return true;} return cdialog: pretranslatemessage (PMSG );}
Save, F5 compile and run the test, everything is OK!