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. How to get datas from an edit control (in the toolbar) by pressing return (enter) ?

How to get datas from an edit control (in the toolbar) by pressing return (enter) ?

Scheduled Pinned Locked Moved C / C++ / MFC
helpphptutorialquestion
24 Posts 4 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.
  • C CrocodileBuck

    Hi Mr.Salsbery, no problem, here is the zip: http://www.filehosting.at/files/download.php?file=28f8239afa7e8afc1de1773edd074a02 best regards Croc

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

    I'll take a look.... In the meantime, see if adding this to the CMyEdit class works: Add to CMyEdit.h, in the CMyEdit class declaration:

    public:
        virtual BOOL PreTranslateMessage(MSG* pMsg);

    Add to CMyEdit.cpp

    BOOL CTestEdit::PreTranslateMessage(MSG* pMsg)
    {
        if (pMsg->message == WM_KEYDOWN && VK_RETURN == pMsg->wParam)
        {
            return TRUE;
        }
        else if (pMsg->message == WM_KEYUP && VK_RETURN == pMsg->wParam)
        {
            // Do stuff!

    return TRUE;
        }

    return CEdit::PreTranslateMessage(pMsg);
    }

    Maybe that will work better! :) Mark

    Mark Salsbery Microsoft MVP - Visual C++ :java:

    L 1 Reply Last reply
    0
    • M Mark Salsbery

      I'll take a look.... In the meantime, see if adding this to the CMyEdit class works: Add to CMyEdit.h, in the CMyEdit class declaration:

      public:
          virtual BOOL PreTranslateMessage(MSG* pMsg);

      Add to CMyEdit.cpp

      BOOL CTestEdit::PreTranslateMessage(MSG* pMsg)
      {
          if (pMsg->message == WM_KEYDOWN && VK_RETURN == pMsg->wParam)
          {
              return TRUE;
          }
          else if (pMsg->message == WM_KEYUP && VK_RETURN == pMsg->wParam)
          {
              // Do stuff!

      return TRUE;
          }

      return CEdit::PreTranslateMessage(pMsg);
      }

      Maybe that will work better! :) Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #22

      Wow 20 some messages to get text from an edit control? WOW :omg: I can't get myself to read this thread. Be afraid, very afraid. :-D

      led mike

      1 Reply Last reply
      0
      • C CrocodileBuck

        Hi Mr.Salsbery, no problem, here is the zip: http://www.filehosting.at/files/download.php?file=28f8239afa7e8afc1de1773edd074a02 best regards Croc

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

        Ok, I steered you wrong with the enter key, sorry.  Change your CMyEdit class like this and it works fine in your code:

        // MyEdit.h

        #pragma once

        class CMyEdit : public CEdit
        {
            DECLARE_DYNAMIC(CMyEdit)
               
        public:
            CMyEdit();
            virtual ~CMyEdit();

        virtual BOOL PreTranslateMessage(MSG* pMsg);
           
        protected:
            DECLARE_MESSAGE_MAP()
        };

        ///////////////////////////////////////////////////////////////////////////

        // MyEdit.cpp

        #include "stdafx.h"
        #include "MyEdit.h"

        IMPLEMENT_DYNAMIC(CMyEdit, CEdit)

        CMyEdit::CMyEdit() : CEdit()
        {
        }

        CMyEdit::~CMyEdit()
        {
        }

        BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
        END_MESSAGE_MAP()

        BOOL CMyEdit::PreTranslateMessage(MSG* pMsg)
        {
            if (pMsg->message == WM_KEYDOWN && VK_RETURN == pMsg->wParam)
            {
                return TRUE;
            }
            else if (pMsg->message == WM_KEYUP && VK_RETURN == pMsg->wParam)
            {
                // Do stuff!

        MessageBox("Works","Works" ,MB_OK);

        return TRUE;
            }

        return CEdit::PreTranslateMessage(pMsg);
        }

        Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        C 1 Reply Last reply
        0
        • M Mark Salsbery

          Ok, I steered you wrong with the enter key, sorry.  Change your CMyEdit class like this and it works fine in your code:

          // MyEdit.h

          #pragma once

          class CMyEdit : public CEdit
          {
              DECLARE_DYNAMIC(CMyEdit)
                 
          public:
              CMyEdit();
              virtual ~CMyEdit();

          virtual BOOL PreTranslateMessage(MSG* pMsg);
             
          protected:
              DECLARE_MESSAGE_MAP()
          };

          ///////////////////////////////////////////////////////////////////////////

          // MyEdit.cpp

          #include "stdafx.h"
          #include "MyEdit.h"

          IMPLEMENT_DYNAMIC(CMyEdit, CEdit)

          CMyEdit::CMyEdit() : CEdit()
          {
          }

          CMyEdit::~CMyEdit()
          {
          }

          BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
          END_MESSAGE_MAP()

          BOOL CMyEdit::PreTranslateMessage(MSG* pMsg)
          {
              if (pMsg->message == WM_KEYDOWN && VK_RETURN == pMsg->wParam)
              {
                  return TRUE;
              }
              else if (pMsg->message == WM_KEYUP && VK_RETURN == pMsg->wParam)
              {
                  // Do stuff!

          MessageBox("Works","Works" ,MB_OK);

          return TRUE;
              }

          return CEdit::PreTranslateMessage(pMsg);
          }

          Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          C Offline
          C Offline
          CrocodileBuck
          wrote on last edited by
          #24

          Thanx Mr. Salsbery, many, many Thanx ! no i will go to bed ;) :laugh: :laugh: :-D Perhabs tomorrow i have some questions about the code, but meanwhile 10000000 Thanx ;)) Croc

          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