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. ATL / WTL / STL
  4. Getting notification on <CR> from Edit control

Getting notification on <CR> from Edit control

Scheduled Pinned Locked Moved ATL / WTL / STL
c++csharpvisual-studiocomhelp
4 Posts 3 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.
  • J Offline
    J Offline
    janman
    wrote on last edited by
    #1

    I have made a dialog-based WTL application in VS.NET. I'm trying to make one edit window act as a command prompt. I would therefore like to receive a notification in the parent dialog when the user presses carriage return in the edit control. I have tried to use the example by Kristian Lippert in his article Subclassing controls in ATL dialogs using WTL[^] but with no luck. It seems that the sub-class does not receive the WM_KEYDOWN or WM_CHAR at all (does receive WM_CHAR when typing some text). First I thought that I could just use the IDOK-notification and use the control ID or the control hWnd parameters of the notification. But they are "empty" no matter which control has the focus when CR is pressed. Any help appreciated. Below is my control-template: #define EN_GOT_RETURN 0x1000 template <class T> class CEditEnterNotificationT : public CWindowImpl<CEditEnterNotificationT<T> , CEdit> { public:     BEGIN_MSG_MAP(CEditEnterNotificationT< T >)         TRACEMSG("CEditEnterNotification");         MESSAGE_HANDLER(WM_CHAR, OnChar)         MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)     END_MSG_MAP()     CEditEnterNotificationT(HWND hWnd = NULL){ }     CEditEnterNotificationT< T >& operator=(HWND hWnd)     {         m_hWnd = hWnd;         return *this;     }     LRESULT OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)     {         //ignore without a beep         switch (wParam)         {             case '\r': //Carriage return                 ATLTRACE("WM_CHAR - CR\n");                 return 0;                 break;         }         return DefWindowProc(uMsg, wParam, lParam);     }

    U S 2 Replies Last reply
    0
    • J janman

      I have made a dialog-based WTL application in VS.NET. I'm trying to make one edit window act as a command prompt. I would therefore like to receive a notification in the parent dialog when the user presses carriage return in the edit control. I have tried to use the example by Kristian Lippert in his article Subclassing controls in ATL dialogs using WTL[^] but with no luck. It seems that the sub-class does not receive the WM_KEYDOWN or WM_CHAR at all (does receive WM_CHAR when typing some text). First I thought that I could just use the IDOK-notification and use the control ID or the control hWnd parameters of the notification. But they are "empty" no matter which control has the focus when CR is pressed. Any help appreciated. Below is my control-template: #define EN_GOT_RETURN 0x1000 template <class T> class CEditEnterNotificationT : public CWindowImpl<CEditEnterNotificationT<T> , CEdit> { public:     BEGIN_MSG_MAP(CEditEnterNotificationT< T >)         TRACEMSG("CEditEnterNotification");         MESSAGE_HANDLER(WM_CHAR, OnChar)         MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)     END_MSG_MAP()     CEditEnterNotificationT(HWND hWnd = NULL){ }     CEditEnterNotificationT< T >& operator=(HWND hWnd)     {         m_hWnd = hWnd;         return *this;     }     LRESULT OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)     {         //ignore without a beep         switch (wParam)         {             case '\r': //Carriage return                 ATLTRACE("WM_CHAR - CR\n");                 return 0;                 break;         }         return DefWindowProc(uMsg, wParam, lParam);     }

      U Offline
      U Offline
      umeca74
      wrote on last edited by
      #2

      your subclassed control should handle WM_GETDLGCODE to tell the parent dialog that it "DLGC_WANTALLKEYS"

      J 1 Reply Last reply
      0
      • U umeca74

        your subclassed control should handle WM_GETDLGCODE to tell the parent dialog that it "DLGC_WANTALLKEYS"

        J Offline
        J Offline
        janman
        wrote on last edited by
        #3

        Thanks alot. That did the trick. I don't think it's mentioned in the book (Pezold). Happy now :)

        1 Reply Last reply
        0
        • J janman

          I have made a dialog-based WTL application in VS.NET. I'm trying to make one edit window act as a command prompt. I would therefore like to receive a notification in the parent dialog when the user presses carriage return in the edit control. I have tried to use the example by Kristian Lippert in his article Subclassing controls in ATL dialogs using WTL[^] but with no luck. It seems that the sub-class does not receive the WM_KEYDOWN or WM_CHAR at all (does receive WM_CHAR when typing some text). First I thought that I could just use the IDOK-notification and use the control ID or the control hWnd parameters of the notification. But they are "empty" no matter which control has the focus when CR is pressed. Any help appreciated. Below is my control-template: #define EN_GOT_RETURN 0x1000 template <class T> class CEditEnterNotificationT : public CWindowImpl<CEditEnterNotificationT<T> , CEdit> { public:     BEGIN_MSG_MAP(CEditEnterNotificationT< T >)         TRACEMSG("CEditEnterNotification");         MESSAGE_HANDLER(WM_CHAR, OnChar)         MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)     END_MSG_MAP()     CEditEnterNotificationT(HWND hWnd = NULL){ }     CEditEnterNotificationT< T >& operator=(HWND hWnd)     {         m_hWnd = hWnd;         return *this;     }     LRESULT OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)     {         //ignore without a beep         switch (wParam)         {             case '\r': //Carriage return                 ATLTRACE("WM_CHAR - CR\n");                 return 0;                 break;         }         return DefWindowProc(uMsg, wParam, lParam);     }

          S Offline
          S Offline
          Simon Cooke
          wrote on last edited by
          #4

          Make sure that Want Return is set in the dialog editor.

          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