home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 May
/
VPR9705A.ISO
/
VPR_DATA
/
PROGRAM
/
Delphi
/
User_vcl
/
apbar101
/
AppBar.pas
< prev
Wrap
Pascal/Delphi Source File
|
1996-12-01
|
7KB
|
267 lines
unit AppBar;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ShellAPI;
const
WM_APPBARcb = WM_USER;
type
TBar = 8..1000;
TPos = (tpTop, tpBottom, tpLeft, tpRight);
TWindowMove = procedure(R: TRect) of object;
TActivate = procedure(Sender: TObject) of object;
TDeactivate = procedure(Sender: TObject) of object;
TAppBar = class(TComponent)
private
First: Bool;
FBarWidth: TBar;
FBarHeight: TBar;
FPosition: TPos;
FAutoHide: Bool;
FAutoMove: Bool;
FEnable: Bool;
FWnd: Hwnd;
Fabd: TAppBarData;
NewP: TFarProc;
OldP: TFarProc;
FWindowMove:TWindowMove;
FActivate :TActivate;
FDeactivate:TDeactivate;
procedure SetBarWidth(V: TBar);
procedure SetBarHeight(V: TBar);
procedure SetPosition(V: TPos);
procedure SetAutoHide(V: Bool);
procedure SetEnable(V: Bool);
protected
procedure Loaded; override;
procedure InstallAppBar(F: Bool);
procedure SetPosAppBar;
procedure WndProc(var Msg: TMessage);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property BarWidth: TBar read FBarWidth write SetBarWidth;
property BarHeight: TBar read FBarHeight write SetBarHeight;
property Position: TPos read FPosition write SetPosition;
property AutoHide: Bool read FAutoHide write SetAutoHide;
property AutoMove: Bool read FAutoMove write FAutoMove;
property Enable: Bool read FEnable write SetEnable;
property OnWindowMove: TWindowMove read FWindowMove write FWindowMove;
property OnActivate: TActivate read FActivate write FActivate;
property OnDeactivate: TDeactivate read FDeactivate write FDeactivate;
end;
procedure Register;
implementation
//------------------------------------------------------------------------------
procedure Register;
begin
RegisterComponents('SoH', [TAppBar]);
end;
//------------------------------------------------------------------------------
constructor TAppBar.Create(AOwner: TComponent);
var
L: Longint;
begin
Inherited Create(AOwner);
First:=False;
Fwnd:=TForm(AOwner).Handle;
NewP:=MakeObjectInstance(WndProc);
OldP:=Pointer(SetWindowLong(Fwnd, GWL_WNDPROC, Longint(NewP)));
FEnable := True;
FAutoHide := False;
FAutoMove := True;
FBarWidth := 30;
FBarHeight:= 30;
if csDesigning in ComponentState then Exit;
L:=GetWindowLong(Fwnd, GWL_EXSTYLE);
SetWindowLong(Fwnd, GWL_EXSTYLE, L or $0080);
end;
//------------------------------------------------------------------------------
procedure TAppBar.Loaded;
begin
inherited Loaded;
First:=True;
if FEnable then InstallAppBar(True);
end;
//------------------------------------------------------------------------------
destructor TAppBar.Destroy;
begin
if FEnable then InstallAppBar(False);
SetWindowLong(Fwnd, GWL_WNDPROC, Longint(OldP));
FreeObjectInstance(NewP);
Inherited;
end;
//------------------------------------------------------------------------------
procedure TAppBar.SetBarWidth(V: TBar);
begin
if FBarWidth<>V then
begin
FBarWidth:=V;
SetPosAppBar;
end;
end;
//------------------------------------------------------------------------------
procedure TAppBar.SetBarHeight(V: TBar);
begin
if FBarHeight<>V then
begin
FBarHeight:=V;
SetPosAppBar;
end;
end;
//------------------------------------------------------------------------------
procedure TAppBar.SetPosition(V: TPos);
begin
if FPosition<>V then
begin
FPosition:=V;
SetPosAppBar;
end;
end;
//------------------------------------------------------------------------------
procedure TAppBar.SetAutoHide(V: Bool);
begin
if FAutoHide<>V then
begin
if FEnable then
begin
FAutoHide:=V;
SetPosAppBar;
end;
end;
end;
//------------------------------------------------------------------------------
procedure TAppBar.SetEnable(V: Bool);
begin
if FEnable<>V then
begin
FEnable:=V;
InstallAppBar(V);
end;
end;
//------------------------------------------------------------------------------
procedure TAppBar.InstallAppBar(F: Bool);
var
R: TRect;
begin
if csDesigning in ComponentState then Exit;
Fabd.cbSize:=SizeOf(TAppBarData);
Fabd.hWnd:=Fwnd;
Fabd.uCallBackMessage:=WM_APPBARcb;
if F then
begin
ShAppBarMessage(ABM_NEW, Fabd);
SetPosAppBar;
end else
ShAppBarMessage(ABM_REMOVE, Fabd);
end;
//------------------------------------------------------------------------------
procedure TAppBar.SetPosAppBar;
var
R: TRect;
B: Bool;
Bw,Bh: Integer;
begin
if csDesigning in ComponentState then Exit;
if FEnable=False then Exit;
if First=False then Exit;
Fabd.lParam:=0;
ShAppBarMessage(ABM_SETAUTOHIDEBAR, Fabd);
case Position of
tpTop: Fabd.uEdge:=ABE_TOP;
tpBottom: Fabd.uEdge:=ABE_BOTTOM;
tpLeft: Fabd.uEdge:=ABE_LEFT;
tpRight: Fabd.uEdge:=ABE_RIGHT;
end;
Fabd.lParam:=Integer(FAutoHide);
ShAppBarMessage(ABM_SETAUTOHIDEBAR, Fabd);
Fabd.RC:=Bounds(0,0,GetSystemMetrics(SM_CXSCREEN)
,GetSystemMetrics(SM_CYSCREEN));
case Position of
tpTop: Fabd.RC.Bottom:=Fabd.RC.Top + BarHeight;
tpBottom: Fabd.RC.Top :=Fabd.RC.Bottom - BarHeight;
tpLeft: Fabd.RC.Right :=Fabd.RC.Left + BarWidth;
tpRight: Fabd.RC.Left :=Fabd.RC.Right - BarWidth;
end;
ShAppBarMessage(ABM_QUERYPOS, Fabd);
case Position of
tpTop: Fabd.RC.Bottom:=Fabd.RC.Top + BarHeight;
tpBottom: Fabd.RC.Top :=Fabd.RC.Bottom - BarHeight;
tpLeft: Fabd.RC.Right :=Fabd.RC.Left + BarWidth;
tpRight: Fabd.RC.Left :=Fabd.RC.Right - BarWidth;
end;
R:=Fabd.RC;
ShAppBarMessage(ABM_SETPOS, Fabd);
Fabd.RC:=R;
if FAutoMove then
MoveWindow(Fwnd, R.Left, R.Top, R.Right-R.Left, R.Bottom-R.Top, True);
if Assigned(OnWindowMove) then OnWindowMove(Fabd.RC);
end;
//------------------------------------------------------------------------------
procedure TAppBar.WndProc(var Msg: TMessage);
var
R: TRect;
begin
case Msg.Msg of
WM_ACTIVATE: begin
ShAppBarMessage(ABM_ACTIVATE, Fabd);
if Bool(Msg.wParam)=True then begin
if Assigned(OnActivate) then OnActivate(Self);
end else begin
if Assigned(OnDeactivate) then OnDeactivate(Self);
end;
end;
WM_WINDOWPOSCHANGED:
ShAppBarMessage(ABM_WINDOWPOSCHANGED, Fabd);
WM_WINDOWPOSCHANGING: ;
WM_APPBARcb: begin
case Msg.wParam of
ABN_POSCHANGED:
SetPosAppBar;
ABN_FULLSCREENAPP: ;
ABN_STATECHANGE: ;
ABN_WINDOWARRANGE:
end;
end;
end;
Msg.Result:=CallWindowProc(OldP, Fwnd, Msg.Msg, Msg.wParam, Msg.lParam);
end;
//------------------------------------------------------------------------------
end.