Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WM_GETDLGCODE and VK_ESCAPE

518 views
Skip to first unread message

Guillermo Prandi

unread,
Mar 26, 2003, 10:08:15 AM3/26/03
to
Hi! I'm writing a text edit control which I subclassed
from CWnd (not from CEdit, for my own reasons). I'm
handling the WM_GETDLGCODE with DLGC_WANTALLKEYS in order
to get VK_TAB and VK_ENTER, which I need, for my control
processes tabs and is multiline. However, I don't need to
process VK_ESCAPE. Since my control will most likely be
used in dialogs, I should pass the VK_ESCAPE code to the
parent window (in order to trigger IDCANCEL, for example),
only that I don't know what's the correct way to do that.
I thought of passing it to CWnd::OnKeyDown(), but it
doesn't work. IsDialogMessage() in the parent always get
TRUE, even if I force a non-zero response to the
WM_KEYDOWN message. What would be the correct way to do
this? Should I PostMessage() the WM_KEYDOWN to the parent
window?

Thanks in advance,

Guille

Ted

unread,
Mar 26, 2003, 4:17:05 PM3/26/03
to
There's a trick you can use to handle only the keys you want in
WM_GETDLGCODE and DLGC_WANTALLKEYS, but handle other keys with the default
handling. You dynamically change to and from DLGC_WANTALLKEYS based on
the current key code being processed. A little known fact is that the
current key being typed is in the wParam of the WM_GETDLGCODE, so you would
do the following (roughly):

if ( Msg.wParam == VK_TAB || Msg.wParam == VK_ENTER) {
Result = (UINT)Default();
Result |= DLGC_WANTALLKEYS;
}
else
Result = (UINT)Default();

return Result;

Ted.


"Guillermo Prandi" <gp-msdn-newsgroups@mailfilter_nospppam_.com.ar> wrote in
message news:3c3201c2f3a9$86faef50$a501...@phx.gbl...

Ted

unread,
Mar 26, 2003, 4:22:41 PM3/26/03
to
Small correction: when I said wParam, it's not the wParam of the
WM_GETDLGCODE, I really meant the wParam member of the MSG structure passed
through the LParam, so

Msg = *(MSG *)LParam;

Ted.

"Ted" <T...@t--x.org> wrote in message
news:eBCFO098...@TK2MSFTNGP10.phx.gbl...

Guillermo Prandi

unread,
Mar 26, 2003, 4:40:46 PM3/26/03
to
Thanks. I thought of an approach like that, but since the
overridable OnGetDlgCode() doesn't give me the MSG struct,
I dropped the idea. I'll try to do what you say by
changing the override, if I can. I can always override the
WindowProc function, of course.

Guille

>.
>

Ted

unread,
Mar 26, 2003, 5:35:22 PM3/26/03
to
you can always get the LParam value by calling CWnd::GetCurrentMessage from
OnGetDlgCode,

e.g.

const MSG* pMsg = GetCurrentMessage();

MSG msg = *((MSG *)pMsg->lParam);

Crazy stuff, getting a message from an lparam from a message,

Ted.

"Guillermo Prandi" <gp-msdn-newsgroups@mailfilter_nospppam_.com.ar> wrote in

message news:3f9601c2f3e0$5c2aae00$a301...@phx.gbl...

Guillermo Prandi

unread,
Mar 26, 2003, 6:09:21 PM3/26/03
to

Oh, I didn't know that! Thanks. I'm trying your suggestion
tonight.

Guille

>-----Original Message-----
>you can always get the LParam value by calling
CWnd::GetCurrentMessage from
>OnGetDlgCode,
>
>e.g.
>
>const MSG* pMsg = GetCurrentMessage();
>
>MSG msg = *((MSG *)pMsg->lParam);
>
>Crazy stuff, getting a message from an lparam from a
message,
>
>Ted.
>

>.
>

Guillermo Prandi

unread,
Mar 26, 2003, 7:50:46 PM3/26/03
to

It works like a charm. My code:

UINT CUniEdit::OnGetDlgCode()
{


const MSG *pMsg = GetCurrentMessage();

pMsg = ((const MSG *)pMsg->lParam);

if( pMsg != NULL )
{
if( pMsg->message == WM_KEYDOWN )
{
if( pMsg->wParam == VK_ESCAPE ) return 0;
}
}

return DLGC_WANTALLKEYS | DLGC_WANTARROWS |
DLGC_WANTTAB | DLGC_HASSETSEL | DLGC_WANTCHARS;
}

Thanks a lot, Ted.

Guille

>-----Original Message-----
>you can always get the LParam value by calling
CWnd::GetCurrentMessage from
>OnGetDlgCode,
>
>e.g.
>
>const MSG* pMsg = GetCurrentMessage();
>
>MSG msg = *((MSG *)pMsg->lParam);
>
>Crazy stuff, getting a message from an lparam from a
message,
>
>Ted.
>

>.
>

0 new messages