mfc - How can we make Cedit control text highlighted even though the focus is on other dialog box? -


i have 1 dialog box has edit control(some text in it.) , button(on clicking other dialog box gets open).

i selected(highlighted) text , clicked button, other dialog opened edit control text unselected.

i wanted keep text selected not happening? why is so? ans how can it?

the default behavior edit control hides selection when control loses focus. negate default behavior have apply es_nohidesel edit control style calling cwnd::modifystyle if dynamically create control or want dynamically change style. static resource can set no hide selection property resource editor.

note, however, when edit control gains focus entire contents selected default. if not want have subclass edit control (both in c++ sense win32-api sense). deriving cedit, add on_wm_getdlgcode handler , mask out dlgc_hassetsel bit:

class cpreservingselectionedit : public cedit { protected:     declare_message_map(); public:     afx_msg uint ongetdlgcode()     {         uint uicode = cedit::ongetdlgcode();         uicode &= ~dlgc_hassetsel;         return uicode;     } };  begin_message_map( cpreservingselectionedit, cedit )     on_wm_getdlgcode() end_message_map() 

to subclass control have attach derived class control. straightforward way add ddx_control-statement dodataexchange implementation:

void cmydlg::dodataexchange( cdataexchange* pdx ) {     cdialogex::dodataexchange( pdx );     ddx_control( pdx, idc_edit1, m_preservingselectionedit ); } 

where idc_edit1 control identifier of control want subclass , m_preservingselectionedit member variable of dialog class of type cpreservingselectionedit.

note also, behavior , visual representation independent of each other. can apply each individually. consequently if want edit control retain selection without changing visual feedback can implement changes laid out in second part of answer alone.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -