CYYYView() : m_subclassedEdit(NULL, this, 1) {}
Rest of pertinent code:
CContainedWindowT<WTL::CEdit> m_subclassedEdit;
BOOL PreTranslateMessage(MSG* pMsg);
BEGIN_MSG_MAP(CYYYView)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
ALT_MSG_MAP(1)
MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
END_MSG_MAP()
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
m_subclassedEdit.SubclassWindow(GetDlgItem(IDC_EDIT2));
return 0;
}
LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
switch (wParam)
{
case VK_RETURN:
MessageBox("Caught Enter key");
return FALSE;
}
return ::DefWindowProc(this->m_hWnd, uMsg, wParam, lParam);
}
I subclass the control and expect to be able to intercept the Enter key
being pressed. But for some reason I don't get anything. I CAN intercept
WM_CHAR messages - if I put them in the Alternative msg map, but I want the
Enter/Return key.
Any help would be much appreciated.
Angus Comber
I always thought that if a window has a child parent relationship
established on creation that it would be enough for messages to permeate
through the windows.
I think you got two ways to fix it.
In the main frame PreTranslateMessage function catch the key you interested
in and forward it to the window.
Something like
if(pMsg->wParam == VK_RETURN)
return (BOOL)::SendMessage(m_View.m_hWnd, WM_FORWARDMSG, 0,
(LPARAM)
Tip: if you want to get a feel for this ask the WTL wizard to make a MDI
window and you will see the frame work.
This can get messy but if you have say a split window with various views,
its quite a nice way to direct messages to the active view.
The other way which forces the propagation is to
Inherit from CMessageFilter
Add this in the initializer
_AppModule.GetMessageLoop()->AddMessageFilter(this);
Add this when the dialog or other window when it closes
_AppModule.GetMessageLoop()->RemoveMessageFilter(this);
I beleive this will progate all messages not processed in the chain, that is
I think if you intercept the KeyDown in the mainframe, you wont get it in
the dialog.
My little wisdom says go the first way if you have split windows, go the
second way for popup dialogs.
Maybe "Igor the Great" can comment on this
Oh other thing I have found is that tooltips also give trouble in some cases
and the reason is the mouse move message is not getting through. This also
fixes that.
"Angus Comber" <an...@iteloffice.com> wrote in message
news:#sgJJ04B...@TK2MSFTNGP11.phx.gbl...
If your Edit control is multiline (has ES_MULTILINE style) you can also
add ES_WANTRETURN style. This will cause it to report DLGC_WANTALLKEYS
in response to WM_GETDLGCODE. Alternatively, you can subclass the
control (which you do already) and process WM_GETDLGCODE yourself. This
way you can trick IsDialogMessage into giving Enter keypress to the
control. Yet another way is to modify PreTranslateMessage and check for
Enter key directed to your Edit control there, before calling
IsDialogMessage.
--
With best wishes,
Igor Tandetnik
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
"Angus Comber" <an...@iteloffice.com> wrote in message
news:#sgJJ04B...@TK2MSFTNGP11.phx.gbl...