the case: i'd make shortcuts numpad users can use application fast. implemented in pretranslatemessage , worked.
but case have edit control user should enter number. @ time user has focus on edit control (cedit), shortcuts should disabled.
to cover this, added
cwnd* pcontrol; pcontrol = this->getfocus(); if(!(pcontrol->iskindof(runtime_class(cedit)))){ but whenever application dialog loses focus, closes (see video) , following exeption:

this full code:
// handles keypresses fast acces of functions bool copenfilesdlg::pretranslatemessage(msg *pmsg){ cwnd* pcontrol; pcontrol = this->getfocus(); if(!(pcontrol->iskindof(runtime_class(cedit)))){ //when statement commented program doesn't crash if(pmsg->message == wm_keydown) { if((pmsg->wparam == 0x31 || pmsg->wparam == vk_numpad1)) somefunction(); else if((pmsg->wparam == 0x33 || pmsg->wparam == vk_numpad3)){ someotherfunction(); } } } return cdialog::pretranslatemessage(pmsg); } now question: why program crash when not in focus , how check if focus on edit control in proper way?
cwnd::getfocus returns pointer window has current focus, or null if there no focus window.
pcontrol = this->getfocus(); if ( pcontrol != null ) { if(!(pcontrol->iskindof(runtime_class(cedit)))) ... } another way compare pcontrol value pointer cedit class member (or members) of dialog class. example, if cedit m_edit edit box class member, test:
if ( pcontrol == (cwnd*)&m_edit ) { // focus on m_edit control }
Comments
Post a Comment