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

Enter As Tab

2 views
Skip to first unread message

George Boutwell

unread,
Dec 10, 1998, 3:00:00 AM12/10/98
to
I know this has been asked dozens of times. I've looked at the archives
and seen the code put up... I've come up with the following:

void TreatEnterAsTab(WORD &io_wKey)
{
if (io_wKey == VK_RETURN)
{
if (GetKeyState(VK_SHIFT) < 0)
{
Screen->ActiveForm->Perform(WM_NEXTDLGCTL, true, false);
}
else
{
Screen->ActiveForm->Perform(WM_NEXTDLGCTL, false, false);
} // End if
io_wKey = 0;
} // End if
}

This has 2 shortcomings:

1) It sometimes beeps and other times doesn't. Terribly unprofessional

2) It only works for controls. I need something that would work in
Grids and just about any place.

Any ideas, suggestions?


--
George Boutwell,
Programmer
Valley Hope Association

For success in e-mailing remove 'REMOVE-THIS' from my e-mail
address.

Alex Bakaev [TeamB]

unread,
Dec 10, 1998, 3:00:00 AM12/10/98
to
You can change the value of the io_wKey to the value of <enter> and call
default handler.

HTH,
Alex

George Boutwell wrote:
[snip]

George Boutwell

unread,
Dec 10, 1998, 3:00:00 AM12/10/98
to
I don't follow. The io_wKey already is <enter> or rather VK_RETURN,
What 'default handler' are you talking about?

--

George Boutwell,
Programmer
Valley Hope Association

Home Page: http://www.nisc.net/gboutwel
E-Mail: For sucess in sending me e-mail delete 'REMOVE-THIS'
from my e-mail address.

Alex Bakaev [TeamB]

unread,
Dec 11, 1998, 3:00:00 AM12/11/98
to
I meant change it to VK_TAB. Default handler is the one that would be
executed if you didn't have your own.

Alex

George Boutwell

unread,
Dec 13, 1998, 3:00:00 AM12/13/98
to
I'm having trouble (part of it is I'm not too good with Object Pascal)
finding what the default handler is... And then even more trouble trying
to call it within my C++/event code.

Can't I 'bypass' this and change the VK_RETURN key to a VK_TAB key back
at the Windows API? Thus the VCL default handlers and what not will not
care and will handle it accordingly.

Bill Thompson

unread,
Dec 13, 1998, 3:00:00 AM12/13/98
to
George Boutwell wrote:

> I know this has been asked dozens of times. I've looked at the archives
> and seen the code put up... I've come up with the following:

Set the Forms property "Key Preview" to true.

Then under events "OnKeyPress"

void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key)
{

if(Key == VK_RETURN){
Key = 0;
Perform(WM_NEXTDLGCTL,0,0);
}
}
//---------------------------------------------------------------------------


George Boutwell

unread,
Dec 13, 1998, 3:00:00 AM12/13/98
to Bill Thompson
Bill,

I've done this. It causes 'beeps' sometimes and doesn't work on
TStringGrids control...

George

--

Fishface

unread,
Dec 13, 1998, 3:00:00 AM12/13/98
to
George Boutwell wrote in message <36747A22...@valleyhope.com>...

>Bill,
>
>I've done this. It causes 'beeps' sometimes and doesn't work on
>TStringGrids control...

Where and when does it beep?

Also, I am sure you have the TStringGrid::Options goChecked enabled, right?

I was messing with TApplication:: OnMessage and did this:


// Form header file:

void __fastcall AppMessage(tagMSG &Msg, bool &Handled);


// Form .cpp file:

void __fastcall TForm1::FormCreate(TObject *Sender)
{
Application->OnMessage = AppMessage;
}

// -------------------------------------------------------------------------
--

void __fastcall TForm1::AppMessage(tagMSG &Msg, bool &Handled)
{
if(Msg.message == WM_KEYDOWN || Msg.message == WM_KEYUP)
{
if(Msg.wParam == VK_RETURN)
{
// this selectively allows default TRichEdit behavior
TRichEdit *re;
re = dynamic_cast<TRichEdit *>(Screen->ActiveControl);
if(re) return;

Msg.wParam = VK_TAB;
Handled = false; // not necessary (default is false)
}
}
}

It worked OK for what I was doing...

FF

George Boutwell

unread,
Dec 13, 1998, 3:00:00 AM12/13/98
to

Fishface wrote:
>
> >I've done this. It causes 'beeps' sometimes and doesn't work on
> >TStringGrids control...
>
> Where and when does it beep?

I have a login screen for my application, which has two edit controls,
and OK, Cancel buttons. The first edit control (User Name or Number)
beeps when they press enter, the second doesn't.

> Also, I am sure you have the TStringGrid::Options goChecked enabled, > right?

I'll have to check this... The only TStringGrid::Options 'value' I
found to be of any significance on this was the goTabs.

> I was messing with TApplication:: OnMessage and did this:
>
> // Form header file:
>
> void __fastcall AppMessage(tagMSG &Msg, bool &Handled);
>
> // Form .cpp file:
>
> void __fastcall TForm1::FormCreate(TObject *Sender)
> {
> Application->OnMessage = AppMessage;
> }
>
> //

> void __fastcall TForm1::AppMessage(tagMSG &Msg, bool &Handled)
> {
> if(Msg.message == WM_KEYDOWN || Msg.message == WM_KEYUP)
> {
> if(Msg.wParam == VK_RETURN)
> {
> // this selectively allows default TRichEdit behavior
> TRichEdit *re;
> re = dynamic_cast<TRichEdit *>(Screen->ActiveControl);
> if(re) return;
>
> Msg.wParam = VK_TAB;
> Handled = false; // not necessary (default is false)
> }
> }
> }
>
> It worked OK for what I was doing...

Thanks... I'll give this a try.

Fishface

unread,
Dec 13, 1998, 3:00:00 AM12/13/98
to
George Boutwell wrote in message <36748C36...@valleyhope.com>...

>> Also, I am sure you have the TStringGrid::Options goChecked enabled, >
right?
>
>I'll have to check this... The only TStringGrid::Options 'value' I
>found to be of any significance on this was the goTabs.


Whoops! That's what I meant. How'd that happen?! <G>

FF

Bill Thompson

unread,
Dec 14, 1998, 3:00:00 AM12/14/98
to
George Boutwell wrote:

> Bill,


>
> I've done this. It causes 'beeps' sometimes and doesn't work on
> TStringGrids control...
>

I've revise my prior response and added PeekMessage to remove
the message (beep) from the focused control's queue.
I't works with TStringGrid here......so I can't help you there, if I've helped at
all.
-----here's the code
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
MSG msg; // Set message structure needed for PeekMessage

if (Key == VK_RETURN){
Key = 0;
PeekMessage(&msg,GetFocus(), 0, 0, PM_REMOVE); // remove message
PostMessage(Form1->Handle,WM_NEXTDLGCTL,0,0);
}
}

0 new messages