🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.ms-windows.programmer.misc
Article #1632

Re: Enter key in VB

#1632
From: John Grant
Date: Thu, 15 Oct 1992 23:22
38 lines
2509 bytes
In article <1992Oct15.202628.13352@javelin.sim.es.com> gfowler@javelin.sim.es.com (Gary Fowler) writes:

in response to a query about how to make ENTER go to the next field rather than
DEFPUSHBUTTON, Gary replied:

>It is possible, but I would advise against it since it does not conform to
>Windows standards.  The standard is to TAB from one field to the next.  One
>of the advantages of Windows is to have a common look and feel between apps.
>You know what you and the users need, so the choice is up to you.

I totally disagree.  I like standards just as much as the next guy, but I
detest and protest the design of Windows and other dialog boxes that treat
ENTER like an OK button rather than 'next field' button.  I don't have any
problems with TAB & SHIFT-TAB to go forwards and backwards between fields,
but ENTER is too intuitive a keystroke to use to terminate entry of a value
in a field to entrust to such a critical operation as "ok, I'm done".  I
can't count the number of times, I have hit ENTER and cursed as the box
disappears and the operation resumes.  In particular in a search & replace
box, if I enter the search text and hit ENTER, leaving the replace box empty
it will replace my search text with nothing.  This sucks.  So I encourage
everyone to trap ENTER and ignore it (this only applies to dialog boxes
that have 'edit' fields, of course).

My favourite way to do this, is:
	1. don't have any DEFPUSHBUTTONs in your dialog box (OK & CANCEL
	   should be PUSHBUTTON)
        2. create a 'tiny' DEFPUSHBUTTON somewhere in a corner (1x1 size)
           with a normal id (i.e. 123, but not IDOK or IDCANCEL)
        3. in WM_INITDIALOG, make the button invisible:
		ShowWindow(GetDlgItem(hdlg,123),FALSE);
	4. When you get WM_COMMAND, with wparam==123, that means ENTER
	   has been pressed (it hit the DEFPUSHBUTTON), so just issue
	   	PostMessage(hdlg,WM_NEXTDLGCTL,0,0);
Simple, eh?  It avoids having to deal with WM_CHAR, WM_KEYDOWN and all of
that stuff.

everyone to trap the ENTER key 
"
Technical Details
Message-ID: <1992Oct15.232242.26579@emr1.emr.ca>
Path: arc1-ca.pugleaf.net!sparky!uunet!utcsri!torn!cunews!nrcnet0!emr1!jagrant
References: <1992Oct12.105905@axion.bt.co.uk> <36560011@hpgrla.gr.hp.com> <1992Oct15.202628.13352@javelin.sim.es.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.ms-windows.programmer.misc
Path: arc1-ca.pugleaf.net!sparky!uunet!utcsri!torn!cunews!nrcnet0!emr1!jagrant
From: jagrant@emr1.emr.ca (John Grant)
Subject: Re: Enter key in VB
Message-ID: <1992Oct15.232242.26579@emr1.emr.ca>
Organization: Energy, Mines, and Resources, Ottawa
References: <1992Oct12.105905@axion.bt.co.uk> <36560011@hpgrla.gr.hp.com> <1992Oct15.202628.13352@javelin.sim.es.com>
Date: Thu, 15 Oct 1992 23:22:42 GMT
Lines: 38