May 27, 2024, 05:07:11 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Selecting text in an edit control

Started by Bruce Peaslee, January 08, 2006, 12:47:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bruce Peaslee

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.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

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.
Ionic Wind Support Team

Bruce Peaslee

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
ÂÃ,  ÂÃ,  }


Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

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;
}


Ionic Wind Support Team

Bruce Peaslee

Thanks.ÂÃ,  We'll get there yet!  8)
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

If your using a window it is a bit simpler since there is no need for changing the 'this' property of a control. 
Ionic Wind Support Team

Bruce Peaslee

January 09, 2006, 08:48:26 PM #6 Last Edit: January 09, 2006, 09:24:20 PM by peaslee
I'm using a dialog.

Edit:  It works! Definitely one for the binder! Thanks
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles