Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. What am I doing wrong?

What am I doing wrong?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++help
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MyFathersSon
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • M MyFathersSon

      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

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • M Mark Salsbery

        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

        M Offline
        M Offline
        MyFathersSon
        wrote on last edited by
        #3

        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?

        M 1 Reply Last reply
        0
        • M MyFathersSon

          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?

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

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

          M 1 Reply Last reply
          0
          • M Mark Salsbery

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

            M Offline
            M Offline
            MyFathersSon
            wrote on last edited by
            #5

            Cheers Mark, that was very helpful. Thanks for your time

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups