Board index » cppbuilder » CTRL+Tab in TPageControl ?

CTRL+Tab in TPageControl ?


2003-10-29 07:43:21 PM
cppbuilder53
Hi!
Seems that the CTRL+Tab shortcut (move to the next tab) does not work for
TPageControls. Is there an easy way to react on CTRL+Tab in order to change
to the next TTabSheet? There are no keyboard events in TPageControl either.
Regards,
Tino
 
 

Re:CTRL+Tab in TPageControl ?

"Tino Uhlig" < XXXX@XXXXX.COM >wrote:
Quote
[...] Is there an easy way to react on CTRL+Tab in order to
change to the next TTabSheet?
Not exactly. I tested CTRL+Tab and I couldn't detect Tab in
the wParam with the method that I use but I could detect Tab.
Detection was accomplished by intercepting messages that
Windows sends to the application.
Since Tab takes you to the next control in the tab order, once
you detect it being pressed while the current control is the
PageControl, you need to alter the key to VK_RIGHT or VK_LEFT:
//-- in Main.h ----------------------------
private: // User declarations
void __fastcall AppMessage( TMsg &Msg, bool &Handled );
//-- in Main.cpp --------------------------
__fastcall TMain::TMain(TComponent* Owner) : TForm(Owner)
{
Application->OnMessage = AppMessage;
}
//-----------------------------------------
void __fastcall TMain::AppMessage( TMsg &Msg, bool &Handled )
{
if( Msg.message == WM_KEYDOWN || Msg.message == WM_KEYUP )
{
if( Msg.wParam == VK_TAB )
{
TControl* pControl = reinterpret_cast<TControl*>( Form2->PageControl1 );
if( Screen->ActiveControl == pControl )
{
if( (GetKeyState( VK_SHIFT ) & 0x80 ) == 0x80 ) Msg.wParam = VK_LEFT;
else Msg.wParam = VK_RIGHT;
}
}
}
}
//------------------------------------
If you have more than one PageControl, you can 'tag' them by
using the Tag property:
if( Msg.wParam == VK_TAB )
{
TControl* pControl = Screen->ActiveControl;
if( pControl->Tag == 999 )
{
if( (GetKeyState( VK_SHIFT ) & 0x80 ) == 0x80 ) Msg.wParam = VK_LEFT;
else Msg.wParam = VK_RIGHT;
}
}
You can also try to cast the ActiveControl to a PageControl:
if( Msg.wParam == VK_TAB )
{
TPageControl* pControl = dynamic_cast<TPageControl*>( Screen->ActiveControl );
if( pControl )
{
if( (GetKeyState( VK_SHIFT ) & 0x80 ) == 0x80 ) Msg.wParam = VK_LEFT;
else Msg.wParam = VK_RIGHT;
}
}
The only thing left is for you to modify the code so that the
Tab order doesn't get stuck on the PageControl. First try
CTRL+Tab and display the wParam value. If you can detect it,
all you need to do is modify
if( Msg.wParam == VK_TAB )
to
if( Msg.wParam == CtrlTab value )
Otherwise you need to track the change in the current
TabControl and NOT change the keypress value when it's at
either end on the PageControl.
~ JD
 

Re:CTRL+Tab in TPageControl ?

My multi-tabbed utilities program works fine. It uses TPageControl. I can
Ctrl+Tab and Ctrl+Shift+Tab and they work as expected. Have you set the main
Form's KeyPreview property to true? It is on mine.
--
Mark Jacobs
DK Computing
XXXX@XXXXX.COM
"Tino Uhlig" < XXXX@XXXXX.COM >wrote in message
Quote
Hi!

Seems that the CTRL+Tab shortcut (move to the next tab) does not work for
TPageControls. Is there an easy way to react on CTRL+Tab in order to
change
to the next TTabSheet? There are no keyboard events in TPageControl
either.

Regards,
Tino


 

{smallsort}

Re:CTRL+Tab in TPageControl ?

"Mark Jacobs" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
My multi-tabbed utilities program works fine. It uses TPageControl. I can
Ctrl+Tab and Ctrl+Shift+Tab and they work as expected. Have you set the
main
Form's KeyPreview property to true? It is on mine.
Hi Mark,
you are right. I think the point was that I had the TPageControl itself not
defined as a tab stop. So the CTRL+Tab and CTRL+Shift+Tab did not work
either. No surprise after all. Sorry, my mistake.
Before I recognized it I created a new TPageControl descendant where I had
overwritten the KeyDown event. While for this purpose useless (because
CTRL+Tab is working also without it) maybe someone can still use the code as
a template for reacting on keyboard events in a TPageControl.
So here 's the code - nothing special really just the obvious stuff:
MyPageControl.cpp:
void __fastcall TMyPageControl::KeyDown(Word &Key, Classes::TShiftState
Shift) {
if (OnKeyDown) OnKeyDown(this, Key, Shift);
if (Key == VK_TAB && Shift.Contains(ssCtrl) ) {
if ( Shift.Contains(ssShift) ) {
SelectNextPage(true);
} else {
SelectNextPage(false);
}
}
}
MyPageControl.h:
class TMyPageControl : public TPageControl {
protected:
DYNAMIC void __fastcall KeyDown(Word &Key, Classes::TShiftState Shift);
public:
__fastcall virtual TMyPageControl(Classes::TComponent* AOwner) :
TPageControl(AOwner) { };
__fastcall TMyPageControl(HWND ParentWindow) : TPageControl(ParentWindow)
{ }
};