What am I doing wrong?
-
I've used MFC to create a custom control: An Ellipse with an edit control inside, so it appears as a circular edit box. Problem is, I can't get the data out from the edit control whenever I type anything in. I'm using the windows message handler WM_CHAR, but I fear that that message handler is only interested in the rectangle and not the edit control. How do I get access to the edit control's data? Thanks
-
I've used MFC to create a custom control: An Ellipse with an edit control inside, so it appears as a circular edit box. Problem is, I can't get the data out from the edit control whenever I type anything in. I'm using the windows message handler WM_CHAR, but I fear that that message handler is only interested in the rectangle and not the edit control. How do I get access to the edit control's data? Thanks
MyFathersSon wrote:
Problem is, I can't get the data out from the edit control whenever I type anything in
Maybe these will help? Three ways to get text from an edit control: CEdit::GetWindowText() EM_GETLINE message to edit control WM_GETTEXT message to edit control
-
MyFathersSon wrote:
Problem is, I can't get the data out from the edit control whenever I type anything in
Maybe these will help? Three ways to get text from an edit control: CEdit::GetWindowText() EM_GETLINE message to edit control WM_GETTEXT message to edit control
Cheers Mark, Unfortunately I feel that the code might be causing problems. I code the control as follows: void CEditableCircleCtrl::DrawControl()//called by OnDraw method { CDC *pDC = GetDC(); if(pDC == NULL) { return; } CRect circlerect; //draw the round rectangle circlerect.top = 0; circlerect.left = 0; circlerect.bottom = 40; circlerect.right = 40; pDC->Ellipse(circlerect); } ... int CEditableCircleCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (COleControl::OnCreate(lpCreateStruct) == -1) return -1; //create the edit box editrect.top = 13; editrect.left = 6; editrect.bottom = 28; editrect.right = 36; editctrl.Create(WS_VISIBLE|WS_CHILD|ES_CENTER,editrect, this, 0); return 0; } How can I get hold of the text? Am I doing something wrong? WM_CHAR doesn't capture any text entered in the control. Where would I place any of your suggestions?
-
Cheers Mark, Unfortunately I feel that the code might be causing problems. I code the control as follows: void CEditableCircleCtrl::DrawControl()//called by OnDraw method { CDC *pDC = GetDC(); if(pDC == NULL) { return; } CRect circlerect; //draw the round rectangle circlerect.top = 0; circlerect.left = 0; circlerect.bottom = 40; circlerect.right = 40; pDC->Ellipse(circlerect); } ... int CEditableCircleCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (COleControl::OnCreate(lpCreateStruct) == -1) return -1; //create the edit box editrect.top = 13; editrect.left = 6; editrect.bottom = 28; editrect.right = 36; editctrl.Create(WS_VISIBLE|WS_CHILD|ES_CENTER,editrect, this, 0); return 0; } How can I get hold of the text? Am I doing something wrong? WM_CHAR doesn't capture any text entered in the control. Where would I place any of your suggestions?
WM_CHAR would be sent to your editctrl object (which I assume is a CEdit(?)) so you'd need to override CEdit and in your derived class handle WM_CHAR. That's if you really need to intercept every char as it is entered by the user. Anytime you want to extract the text from the edit control (after it is created, of course) you can use something like
// Copy contents of edit control to a character array...
TCHAR szBuffer = new TCHAR[editctrl.GetWindowTextLength() + 1];
editctrl.GetWindowText(szBuffer, GetWindowTextLength() + 1);or
// Copy contents of edit control to a CString...
CString str;
editctrl.GetWindowText(str); -
WM_CHAR would be sent to your editctrl object (which I assume is a CEdit(?)) so you'd need to override CEdit and in your derived class handle WM_CHAR. That's if you really need to intercept every char as it is entered by the user. Anytime you want to extract the text from the edit control (after it is created, of course) you can use something like
// Copy contents of edit control to a character array...
TCHAR szBuffer = new TCHAR[editctrl.GetWindowTextLength() + 1];
editctrl.GetWindowText(szBuffer, GetWindowTextLength() + 1);or
// Copy contents of edit control to a CString...
CString str;
editctrl.GetWindowText(str);Cheers Mark, that was very helpful. Thanks for your time