community.borland.com

Article #16315: Making accelerators work with a TPageControl

 Technical Information Database

TI1315D.txt - Making accelerators work with a TPageControl

Category   :VCL
Platform   :All-32Bit
Product    :All32Bit,   

Description:
The TPageControl found on the Win95 page of the Component 
Palette does not currently work with accelerators. However, 
it is possible to create a descendant of TPageControl which 
includes this feature. 

The component shown in the code to follow is such a control. 
This TPageControl descendant captures the CM_DIALOGCHAR message. 
This allows you to capture key strokes that may be accelerators 
for a given form. The CMDialogChar message handler uses the 
IsAccel function to determine if the captured key code refers 
to an accelerator on one of the TPageControls pages. If so, 
the appropriate page is made active and is given focus. 

unit tapage;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, 
  Dialogs, ComCtrls;

type

  TAPageControl = class(TPageControl)
  private
    procedure CMDialogChar(var Msg: TCMDialogChar); message 
     CM_DIALOGCHAR;
  end;

procedure Register;

implementation

procedure TAPageControl.CMDialogChar(var Msg: TCMDialogChar);
var
  i: Integer;
  S: String;
begin
  if Enabled then
    for I := 0 to PageCount - 1 do
      if IsAccel(Msg.CharCode, Pages[i].Caption) and
        Pages[I].TabVisible then begin
        Msg.Result := 1;
        ActivePage := Pages[I];
        Change;
        Exit; // exit for loop.
      end;
  inherited;
end;

procedure Register;
begin
  RegisterComponents('Test', [TAPageControl]);
end;

end.

Reference:
 

3/26/99 11:54:06 AM
 

Last Modified: 01-SEP-99