IonicWind Software

Aurora Compiler => GUI => Topic started by: Bruce Peaslee on January 08, 2006, 12:47:35 PM

Title: Selecting text in an edit control
Post by: Bruce Peaslee on January 08, 2006, 12:47:35 PM
In my dialog, when I tab into an edit control, the current text is becomes selected. But I can't figure out a way to get all of the text selected when I enter the control by clicking on it with the mouse.
Title: Re: Selecting text in an edit control
Post by: Ionic Wind Support Team on January 08, 2006, 12:51:20 PM
edit->SetSel(0,-1)

However you'll have to create your own edit class, derived from CEdit, and override OnLButtonDown.  The default behaviour for a Windows edit control is to remove the selection when you click in it, and move the caret to the character after the click position.
Title: Re: Selecting text in an edit control
Post by: Bruce Peaslee on January 09, 2006, 11:58:51 AM
It makes sense, but I'm having trouble.


class myEdit:CEdit
{
ÂÃ,  // Overridden methods
ÂÃ,  declare OnLButtonDown(int x, int y, int flags), int;
}

MyEdit::OnLButtonDown(int x, int y, int flags), int
{
ÂÃ,  MessageBox(this,"HI","",0);ÂÃ,  // no message box ??
ÂÃ,  Return 0;
}

...

dlg1::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
...
ÂÃ,  myEdit *pEdit;
...
}
...
ÂÃ,  if(nNotifyCode = ENSETFOCUS)
ÂÃ,  ÂÃ,  {
ÂÃ,  ÂÃ,  ÂÃ,  pEdit = GetControl(txtD1BasePrice);
ÂÃ,  ÂÃ,  ÂÃ,  pEdit->SetText("Click"); // this works
ÂÃ,  ÂÃ,  ÂÃ, *(myEdit)pEdit.SetSel(0,-1); // this doesn't
ÂÃ,  ÂÃ,  }


Title: Re: Selecting text in an edit control
Post by: Ionic Wind Support Team on January 09, 2006, 06:10:01 PM
If your using a dialog you'll need to tell the dialog to use your overridden edit control. 


#define EDIT_100 100
import int SetPropA(hwnd as unsigned int,lpString as STRING,hData as unsigned int);


class MyEdit:CEdit
{
declare OnLButtonDown(int x,int y,int flags),int;
}

MyEdit::OnLButtonDown(int x,int y,int flags),int
{
SetFocus();
SetSel(0,-1);
return true; //return true so the edit control doesn't handle the message.
}

class dlg:dialog
{
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
MyEdit *m_pMyEdit;
}

global sub main()
{
dlg d1;
d1.Create(0,0,300,202,0x80C80080,0,"Caption",0);
d1.AddControl(CTEDIT,"Click Me",62,61,164,23,0x50800000,0x200,EDIT_100);

d1.DoModal();
return 0;
}

dlg::OnClose(),int
{
CloseDialog(1);
Delete m_pMyEdit;
return true;
}

dlg::OnInitDialog(),int
{
/* Initialize any controls here */
CEdit *pEdit = GetControl(EDIT_100);
//subclass the control
m_pMyEdit = new(MyEdit,1);
m_pMyEdit->m_hWnd = pEdit->m_hWnd;
SetPropA(m_pMyEdit->m_hWnd,"THIS",m_pMyEdit);
CenterWindow();
return true;
}

dlg::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
select nID
{
case EDIT_100:
/* respond to edit notifications here */
}
return true;
}


Title: Re: Selecting text in an edit control
Post by: Bruce Peaslee on January 09, 2006, 06:25:43 PM
Thanks.ÂÃ,  We'll get there yet!  8)
Title: Re: Selecting text in an edit control
Post by: Ionic Wind Support Team on January 09, 2006, 06:27:26 PM
If your using a window it is a bit simpler since there is no need for changing the 'this' property of a control. 
Title: Re: Selecting text in an edit control
Post by: Bruce Peaslee on January 09, 2006, 08:48:26 PM
I'm using a dialog.

Edit:  It works! Definitely one for the binder! Thanks