Getting notification on <CR> from Edit control
-
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); }
-
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); }
-
your subclassed control should handle WM_GETDLGCODE to tell the parent dialog that it "DLGC_WANTALLKEYS"
-
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); }
Make sure that Want Return is set in the dialog editor.