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.
HTH,
Alex
George Boutwell wrote:
[snip]
--
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
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.
> 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);
}
}
//---------------------------------------------------------------------------
I've done this. It causes 'beeps' sometimes and doesn't work on
TStringGrids control...
George
--
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
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.
>> 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,
>
> 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);
}
}