📄 forms.pas
字号:
begin
Result := True;
if PCheckTaskInfo(Data)^.FocusWnd = Window then
begin
Result := False;
PCheckTaskInfo(Data)^.Found := True;
end;
end;
function ForegroundTask: Boolean;
var
Info: TCheckTaskInfo;
begin
Info.FocusWnd := GetActiveWindow;
Info.Found := False;
EnumThreadWindows(GetCurrentThreadID, @CheckTaskWindow, Longint(@Info));
Result := Info.Found;
end;
function FindGlobalComponent(const Name: string): TComponent;
var
I: Integer;
begin
for I := 0 to Screen.FormCount - 1 do
begin
Result := Screen.Forms[I];
if not (csInline in Result.ComponentState) and
(CompareText(Name, Result.Name) = 0) then Exit;
end;
for I := 0 to Screen.DataModuleCount - 1 do
begin
Result := Screen.DataModules[I];
if CompareText(Name, Result.Name) = 0 then Exit;
end;
Result := nil;
end;
{ CTL3D32.DLL support for NT 3.51 has been removed. Ctl3D properties of
VCL controls use extended window style flags on Win95 and later OS's. }
procedure InitCtl3D;
begin
end;
procedure DoneCtl3D;
begin
end;
function Subclass3DWnd(Wnd: HWnd): Boolean;
begin
Result := False;
end;
procedure Subclass3DDlg(Wnd: HWnd; Flags: Word);
begin
end;
procedure SetAutoSubClass(Enable: Boolean);
begin
end;
{ Allocate an object instance }
function MakeObjectInstance(Method: TWndMethod): Pointer;
begin
{$IFDEF LINUX}
Result := WinUtils.MakeObjectInstance(Method);
{$ENDIF}
{$IFDEF MSWINDOWS}
Result := Classes.MakeObjectInstance(Method);
{$ENDIF}
end;
{ Free an object instance }
procedure FreeObjectInstance(ObjectInstance: Pointer);
begin
{$IFDEF LINUX}
WinUtils.FreeObjectInstance(ObjectInstance);
{$ENDIF}
{$IFDEF MSWINDOWS}
Classes.FreeObjectInstance(ObjectInstance);
{$ENDIF}
end;
function AllocateHWnd(Method: TWndMethod): HWND;
begin
{$IFDEF LINUX}
Result := WinUtils.AllocateHWnd(Method);
{$ENDIF}
{$IFDEF MSWINDOWS}
Result := Classes.AllocateHWnd(Method);
{$ENDIF}
end;
procedure DeallocateHWnd(Wnd: HWND);
begin
{$IFDEF LINUX}
WinUtils.DeallocateHWnd(Wnd);
{$ENDIF}
{$IFDEF MSWINDOWS}
Classes.DeallocateHWnd(Wnd);
{$ENDIF}
end;
{ Utility mapping functions }
{ Convert mouse message to TMouseButton }
function KeysToShiftState(Keys: Word): TShiftState;
begin
Result := [];
if Keys and MK_SHIFT <> 0 then Include(Result, ssShift);
if Keys and MK_CONTROL <> 0 then Include(Result, ssCtrl);
if Keys and MK_LBUTTON <> 0 then Include(Result, ssLeft);
if Keys and MK_RBUTTON <> 0 then Include(Result, ssRight);
if Keys and MK_MBUTTON <> 0 then Include(Result, ssMiddle);
if GetKeyState(VK_MENU) < 0 then Include(Result, ssAlt);
end;
{ Convert keyboard message data to TShiftState }
function KeyDataToShiftState(KeyData: Longint): TShiftState;
const
AltMask = $20000000;
{$IFDEF LINUX}
CtrlMask = $10000000;
ShiftMask = $08000000;
{$ENDIF}
begin
Result := [];
if GetKeyState(VK_SHIFT) < 0 then Include(Result, ssShift);
if GetKeyState(VK_CONTROL) < 0 then Include(Result, ssCtrl);
if KeyData and AltMask <> 0 then Include(Result, ssAlt);
{$IFDEF LINUX}
if KeyData and CtrlMask <> 0 then Include(Result, ssCtrl);
if KeyData and ShiftMask <> 0 then Include(Result, ssShift);
{$ENDIF}
end;
{ Convert GetKeyboardState output to TShiftState }
function KeyboardStateToShiftState(const KeyboardState: TKeyboardState): TShiftState;
begin
Result := [];
if KeyboardState[VK_SHIFT] and $80 <> 0 then Include(Result, ssShift);
if KeyboardState[VK_CONTROL] and $80 <> 0 then Include(Result, ssCtrl);
if KeyboardState[VK_MENU] and $80 <> 0 then Include(Result, ssAlt);
if KeyboardState[VK_LBUTTON] and $80 <> 0 then Include(Result, ssLeft);
if KeyboardState[VK_RBUTTON] and $80 <> 0 then Include(Result, ssRight);
if KeyboardState[VK_MBUTTON] and $80 <> 0 then Include(Result, ssMiddle);
end;
{ Calls GetKeyboardState and converts output to TShiftState }
function KeyboardStateToShiftState: TShiftState; overload;
var
KeyState: TKeyBoardState;
begin
GetKeyboardState(KeyState);
Result := KeyboardStateToShiftState(KeyState);
end;
function IsAccel(VK: Word; const Str: string): Boolean;
begin
Result := CompareText(Char(VK), GetHotKey(Str)) = 0;
end;
{ Form utility functions }
function GetParentForm(Control: TControl): TCustomForm;
begin
while Control.Parent <> nil do Control := Control.Parent;
if Control is TCustomForm then
Result := TCustomForm(Control) else
Result := nil;
end;
function ValidParentForm(Control: TControl): TCustomForm;
begin
Result := GetParentForm(Control);
if Result = nil then
raise EInvalidOperation.CreateFmt(SParentRequired, [Control.Name]);
end;
{ TControlScrollBar }
constructor TControlScrollBar.Create(AControl: TScrollingWinControl;
AKind: TScrollBarKind);
begin
inherited Create;
FControl := AControl;
FKind := AKind;
FPageIncrement := 80;
FIncrement := FPageIncrement div 10;
FVisible := True;
FDelay := 10;
FLineDiv := 4;
FPageDiv := 12;
FColor := clBtnHighlight;
FParentColor := True;
FUpdateNeeded := True;
end;
function TControlScrollBar.IsIncrementStored: Boolean;
begin
Result := not Smooth;
end;
procedure TControlScrollBar.Assign(Source: TPersistent);
begin
if Source is TControlScrollBar then
begin
Visible := TControlScrollBar(Source).Visible;
Range := TControlScrollBar(Source).Range;
Position := TControlScrollBar(Source).Position;
Increment := TControlScrollBar(Source).Increment;
Exit;
end;
inherited Assign(Source);
end;
procedure TControlScrollBar.ChangeBiDiPosition;
begin
if Kind = sbHorizontal then
if IsScrollBarVisible then
if not FControl.UseRightToLeftScrollBar then
Position := 0
else
Position := Range;
end;
procedure TControlScrollBar.CalcAutoRange;
var
I: Integer;
NewRange, AlignMargin: Integer;
procedure ProcessHorz(Control: TControl);
begin
if Control.Visible then
case Control.Align of
alLeft, alNone:
if (Control.Align = alLeft) or (Control.Anchors * [akLeft, akRight] = [akLeft]) then
NewRange := Max(NewRange, Position + Control.Left + Control.Width);
alRight: Inc(AlignMargin, Control.Width);
end;
end;
procedure ProcessVert(Control: TControl);
begin
if Control.Visible then
case Control.Align of
alTop, alNone:
if (Control.Align = alTop) or (Control.Anchors * [akTop, akBottom] = [akTop]) then
NewRange := Max(NewRange, Position + Control.Top + Control.Height);
alBottom: Inc(AlignMargin, Control.Height);
end;
end;
begin
if FControl.FAutoScroll then
begin
if FControl.AutoScrollEnabled then
begin
NewRange := 0;
AlignMargin := 0;
for I := 0 to FControl.ControlCount - 1 do
if Kind = sbHorizontal then
ProcessHorz(FControl.Controls[I]) else
ProcessVert(FControl.Controls[I]);
DoSetRange(NewRange + AlignMargin + Margin);
end
else DoSetRange(0);
end;
end;
function TControlScrollBar.IsScrollBarVisible: Boolean;
var
Style: Longint;
begin
Style := WS_HSCROLL;
if Kind = sbVertical then Style := WS_VSCROLL;
Result := (Visible) and
(GetWindowLong(FControl.Handle, GWL_STYLE) and Style <> 0);
end;
function TControlScrollBar.ControlSize(ControlSB, AssumeSB: Boolean): Integer;
var
BorderAdjust: Integer;
function ScrollBarVisible(Code: Word): Boolean;
var
Style: Longint;
begin
Style := WS_HSCROLL;
if Code = SB_VERT then Style := WS_VSCROLL;
Result := GetWindowLong(FControl.Handle, GWL_STYLE) and Style <> 0;
end;
function Adjustment(Code, Metric: Word): Integer;
begin
Result := 0;
if not ControlSB then
if AssumeSB and not ScrollBarVisible(Code) then
Result := -(GetSystemMetrics(Metric) - BorderAdjust)
else if not AssumeSB and ScrollBarVisible(Code) then
Result := GetSystemMetrics(Metric) - BorderAdjust;
end;
begin
BorderAdjust := Integer(GetWindowLong(FControl.Handle, GWL_STYLE) and
(WS_BORDER or WS_THICKFRAME) <> 0);
if Kind = sbVertical then
Result := FControl.ClientHeight + Adjustment(SB_HORZ, SM_CXHSCROLL) else
Result := FControl.ClientWidth + Adjustment(SB_VERT, SM_CYVSCROLL);
end;
function TControlScrollBar.GetScrollPos: Integer;
begin
Result := 0;
if Visible then Result := Position;
end;
function TControlScrollBar.NeedsScrollBarVisible: Boolean;
begin
Result := FRange > ControlSize(False, False);
end;
procedure TControlScrollBar.ScrollMessage(var Msg: TWMScroll);
var
Incr, FinalIncr, Count: Integer;
CurrentTime, StartTime, ElapsedTime: Longint;
function GetRealScrollPosition: Integer;
var
SI: TScrollInfo;
Code: Integer;
begin
SI.cbSize := SizeOf(TScrollInfo);
SI.fMask := SIF_TRACKPOS;
Code := SB_HORZ;
if FKind = sbVertical then Code := SB_VERT;
Result := Msg.Pos;
if FlatSB_GetScrollInfo(FControl.Handle, Code, SI) then
Result := SI.nTrackPos;
end;
begin
with Msg do
begin
if FSmooth and (ScrollCode in [SB_LINEUP, SB_LINEDOWN, SB_PAGEUP, SB_PAGEDOWN]) then
begin
case ScrollCode of
SB_LINEUP, SB_LINEDOWN:
begin
Incr := FIncrement div FLineDiv;
FinalIncr := FIncrement mod FLineDiv;
Count := FLineDiv;
end;
SB_PAG
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -