silver
silver

Reputation: 41

MFC Highlighting any text editing box when clicked

I need to highlight all the text in the edit box by clicking the edit box As the browser's edit box Site address

This button code works.

m_text.SetFocus();
m_text.SetSel(0, -1);

But the editing box event not working

void CMFCApplication99Dlg::OnEnSetfocusEdit1()
{
    m_text.SetFocus();
    m_text.SetSel(0, -1);
}

Upvotes: 0

Views: 1332

Answers (1)

xMRi
xMRi

Reputation: 15365

The problem is that this is the standard behavior. When you click into an edit control, the location is selected were you point to.

To overcome this behavior, it should be possible to post EM_SETSEL as a window message in your EN_SETCOCUS handler.

void CMFCApplication99Dlg::OnEnSetfocusEdit1()
{
  m_text.PostMessage(EM_SETSEL,0,-1);
}

PS: In your code the additional SetFocus is not needed when are inside the EN_SETFOCUS handler.

Upvotes: 2

Related Questions