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

Respond to ENTER key in a ListView

160 views
Skip to first unread message

Genna

unread,
Dec 22, 2001, 10:36:46 AM12/22/01
to
I can't seem to process te ENTER key in a ListView to select an Item.

I'm using the following code to process a WM_NOTIFY message:

switch(pNotify->code)
{
case NM_DBLCLK:
case NM_RETURN:
SelectProc(Window, lParam);
break;
...

But there never seems to be a NM_RETURN code. Is there a trick to getting
the ENTER key to work?

G.

Jeff Partch

unread,
Dec 22, 2001, 12:13:26 PM12/22/01
to
Hi!

Is this ListView on a dialog box?

Jeff...
--
Please post all follow-ups to the newsgroup only.

"Genna" <gvj_n...@ttd.ca> wrote in message news:OPr3I6viBHA.1932@tkmsftngp04...

Genna

unread,
Dec 22, 2001, 12:41:12 PM12/22/01
to
The ListView is part of a Dialog Box.


Jeff Partch

unread,
Dec 22, 2001, 2:26:08 PM12/22/01
to
Hi!

"Genna" <gvj__n...@ttd.ca> wrote in message news:OnMPq$wiBHA.1012@tkmsftngp03...


> The ListView is part of a Dialog Box.
>

Well, here's what I think the deal is: Unless the control with the focus returns DLGC_WANTMESSAGE in
response to the WM_GETDLGCODE message (wherein the LPARAM is not NULL and is an LPMSG who's message
is WM_KEYDOWN and WPARAM is VK_RETURN), the default dialogbox keyboard interface intercepts the
ENTER key and translates it into a WM_COMMAND message with a wParam value equal to IDOK or the id of
the defpushbutton, and sends it to the DlgProc. I don't think there's an LVS_ style to handle this
so... if this is the situation, one solution would be to subclass the ListView, and handle the
WM_GETDLGCODE message appropriately. Another possibility might be to handle the WM_COMMAND situation
and call your selection proc when the listview has the focus. Another possibility might be to use an
accelerator.

HTH,

Christian ASTOR

unread,
Dec 22, 2001, 2:45:03 PM12/22/01
to

Genna wrote:

> But there never seems to be a NM_RETURN code. Is there a trick to getting
> the ENTER key to work?

I've already answered you : copy-paste =>

"Subclass the Listview, then, in the new proc =>
switch (iMsg)
{
case WM_GETDLGCODE :
{
return DLGC_WANTALLKEYS ;
} break;
}
"

Jeff Partch

unread,
Dec 22, 2001, 3:34:55 PM12/22/01
to
Hi, Christian!

"Christian ASTOR" <cast...@club-internet.fr> wrote in message
news:3C24E2BF...@club-internet.fr...


Isn't DLGC_WANTALLKEYS too inclusive -- it'll trap the TAB key as well as the ESC key for example?
How about something like...

switch (iMsg)
{
case WM_GETDLGCODE:
{
LPMSG pMsg = (LPMSG)lParam;
if (pMsg && (pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_RETURN))
return DLGC_WANTMESSAGE;
}
break;

john klosak

unread,
Jan 5, 2002, 11:35:05 AM1/5/02
to
I've had luck with a diffrent approach

.if uMsg == WM_CHAR
.if wParam == 0Dh
return 0
.endif
.endif

.if uMsg == WM_KEYDOWN
.if wParam == 0dh
invoke SetFocus,handle of desired window

the above monitors the wm_keydown message but doesnt process the 0dh
(carrage return code)

and works for me

John Klosak
klo...@qcvascular.com


"Genna" <gvj_n...@ttd.ca> wrote in message
news:OPr3I6viBHA.1932@tkmsftngp04...

0 new messages