tags:

views:

22

answers:

2

I have CEdit control and I don't want any text to be selected by default. I tried using

    m_txtURL.SetSel(-1, 0, TRUE);

to remove the selection, but to no avail. can some one suggest a way to do achieve that?

I tried to select some characters using the following coding. That too did not work.

m_txtURL.SetSel(-1, 0, TRUE);

Can someone tell me what the problem could be?

A: 

The question is why is your text selected by default?

  • Subclass it using DDX_Control(pDX, IDC_EDIT1, m_txtURL)
  • Set the text m_txtURL.SetWindowText(_T("just some text")) in OnInitDialog

Nothing should be selected.

Nikola Smiljanić
+1  A: 

Now I am able to deselect the text in the Edit control. The edit control, I am using is the first control in the Dialog box, so the by default the first control in the dialog box has been set to focus. From developers' reference:

If OnInitDialog returns nonzero, Windows sets the input focus to the first control in the dialog box. The application can return 0 only if it has explicitly set the input focus to one of the controls in the dialog box.

No what I have done is:

BOOL CIegSettingsDlg::OnInitDialog()
{
    CDialog::OnInitDialog();


    return FALSE;  // return TRUE unless you set the focus to a control
}

By this we indicate to dialog box that, we would take care of focussing a control.

Krishnan