📄 jvjvclutils.pas
字号:
Dest.PixelFormat := Source.PixelFormat;
end;
{$IFDEF VCL}
{ (rb) Duplicate of JvAppUtils.AppTaskbarIcons }
procedure HideFormCaption(FormHandle: HWND; Hide: Boolean);
begin
if Hide then
SetWindowLong(FormHandle, GWL_STYLE,
GetWindowLong(FormHandle, GWL_STYLE) and not WS_CAPTION)
else
SetWindowLong(FormHandle, GWL_STYLE,
GetWindowLong(FormHandle, GWL_STYLE) or WS_CAPTION);
end;
{$ENDIF VCL}
// (rom) a thread to wait would be more elegant, also JCL function available
function Execute(const CommandLine, WorkingDirectory: string): Integer;
{$IFDEF MSWINDOWS}
var
R: Boolean;
ProcessInformation: TProcessInformation;
StartupInfo: TStartupInfo;
ExCode: Cardinal;
begin
Result := 0;
FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
with StartupInfo do
begin
cb := SizeOf(TStartupInfo);
dwFlags := STARTF_USESHOWWINDOW;
wShowWindow := SW_SHOW;
end;
R := CreateProcess(
nil, // Pointer to name of executable module
PChar(CommandLine), // Pointer to command line string
nil, // Pointer to process security attributes
nil, // Pointer to thread security attributes
False, // handle inheritance flag
0, // creation flags
nil, // Pointer to new environment block
PChar(WorkingDirectory), // Pointer to current directory name
StartupInfo, // Pointer to STARTUPINFO
ProcessInformation); // Pointer to PROCESS_INFORMATION
if R then
while (GetExitCodeProcess(ProcessInformation.hProcess, ExCode) and
(ExCode = STILL_ACTIVE)) do
Application.ProcessMessages
else
Result := GetLastError;
end;
{$ENDIF MSWINDOWS}
{$IFDEF UNIX}
begin
if WorkingDirectory = '' then
Result := Libc.system(PChar(Format('cd "%s" ; %s',
[GetCurrentDir, CommandLine])))
else
Result := Libc.system(PChar(Format('cd "%s" ; %s',
[WorkingDirectory, CommandLine])));
end;
{$ENDIF UNIX}
{$IFDEF VCL}
procedure LaunchCpl(const FileName: string);
begin
// rundll32.exe shell32,Control_RunDLL ';
RunDLL32('shell32.dll', 'Control_RunDLL', FileName, True);
// WinExec(PChar(RC_RunCpl + FileName), SW_SHOWNORMAL);
end;
procedure ShowSafeRemovalDialog;
begin
LaunchCpl('HOTPLUG.DLL');
end;
const
{$EXTERNALSYM WM_CPL_LAUNCH}
WM_CPL_LAUNCH = (WM_USER + 1000);
{$EXTERNALSYM WM_CPL_LAUNCHED}
WM_CPL_LAUNCHED = (WM_USER + 1001);
{ (p3) just define enough to make the Cpl unnecessary for us (for the benefit of PE users) }
cCplAddress = 'CPlApplet';
CPL_INIT = 1;
{$EXTERNALSYM CPL_INIT}
CPL_GETCOUNT = 2;
{$EXTERNALSYM CPL_GETCOUNT}
CPL_INQUIRE = 3;
{$EXTERNALSYM CPL_INQUIRE}
CPL_EXIT = 7;
{$EXTERNALSYM CPL_EXIT}
CPL_NEWINQUIRE = 8;
{$EXTERNALSYM CPL_NEWINQUIRE}
type
TCPLApplet = function(hwndCPl: THandle; uMsg: DWORD;
lParam1, lParam2: Longint): Longint; stdcall;
TCPLInfo = packed record
idIcon: Integer;
idName: Integer;
idInfo: Integer;
lData: Longint;
end;
TNewCPLInfoA = packed record
dwSize: DWORD;
dwFlags: DWORD;
dwHelpContext: DWORD;
lData: Longint;
HICON: HICON;
szName: array [0..31] of AnsiChar;
szInfo: array [0..63] of AnsiChar;
szHelpFile: array [0..127] of AnsiChar;
end;
TNewCPLInfoW = packed record
dwSize: DWORD;
dwFlags: DWORD;
dwHelpContext: DWORD;
lData: Longint;
HICON: HICON;
szName: array [0..31] of WideChar;
szInfo: array [0..63] of WideChar;
szHelpFile: array [0..127] of WideChar;
end;
function GetControlPanelApplet(const AFileName: string; Strings: TStrings;
Images: TCustomImageList = nil): Boolean;
var
hLib: HMODULE; // Library Handle to *.cpl file
hIco: HICON;
CplCall: TCPLApplet; // Pointer to CPlApplet() function
I: Longint;
TmpCount, Count: Longint;
S: WideString;
// the three types of information that can be returned
CPLInfo: TCPLInfo;
InfoW: TNewCPLInfoW;
InfoA: TNewCPLInfoA;
HWND: THandle;
begin
Result := False;
hLib := SafeLoadLibrary(AFileName);
if hLib = 0 then
Exit;
HWND := GetForegroundWindow;
TmpCount := Strings.Count;
Strings.BeginUpdate;
try
@CplCall := GetProcAddress(hLib, PChar(cCplAddress));
if not Assigned(CplCall) then
Exit;
CplCall(HWND, CPL_INIT, 0, 0); // Init the *.cpl file
try
Count := CplCall(HWND, CPL_GETCOUNT, 0, 0);
for I := 0 to Count - 1 do
begin
FillChar(InfoW, SizeOf(InfoW), 0);
FillChar(InfoA, SizeOf(InfoA), 0);
FillChar(CPLInfo, SizeOf(CPLInfo), 0);
S := '';
CplCall(HWND, CPL_NEWINQUIRE, I, Longint(@InfoW));
if InfoW.dwSize = SizeOf(InfoW) then
begin
hIco := InfoW.HICON;
S := WideString(InfoW.szName);
end
else
begin
if InfoW.dwSize = SizeOf(InfoA) then
begin
Move(InfoW, InfoA, SizeOf(InfoA));
hIco := CopyIcon(InfoA.HICON);
S := string(InfoA.szName);
end
else
begin
CplCall(HWND, CPL_INQUIRE, I, Longint(@CPLInfo));
LoadStringA(hLib, CPLInfo.idName, InfoA.szName,
SizeOf(InfoA.szName));
hIco := LoadImage(hLib, PChar(CPLInfo.idIcon), IMAGE_ICON, 16, 16,
LR_DEFAULTCOLOR);
S := string(InfoA.szName);
end;
end;
if S <> '' then
begin
S := Format('%s=%s,@%d', [S, AFileName, I]);
if Images <> nil then
begin
hIco := CopyIcon(hIco);
ImageList_AddIcon(Images.Handle, hIco);
Strings.AddObject(S, TObject(Images.Count - 1));
end
else
Strings.AddObject(S, IconToBitmap2(hIco, 16, clMenu));
// (p3) not sure this is really needed...
// DestroyIcon(hIco);
end;
end;
Result := TmpCount < Strings.Count;
finally
CplCall(HWND, CPL_EXIT, 0, 0);
end;
finally
FreeLibrary(hLib);
Strings.EndUpdate;
end;
end;
function GetControlPanelApplets(const APath, AMask: string; Strings: TStrings;
Images: TCustomImageList = nil): Boolean;
var
H: THandle;
F: TSearchRec;
begin
Result := False;
if Strings = nil then
Exit;
H := FindFirst(IncludeTrailingPathDelimiter(APath) + AMask, faAnyFile, F);
if Images <> nil then
begin
Images.Clear;
Images.BkColor := clMenu;
end;
Strings.BeginUpdate;
try
Strings.Clear;
while H = 0 do
begin
if F.Attr and faDirectory = 0 then
// if (F.Name <> '.') and (F.Name <> '..') then
GetControlPanelApplet(APath + F.Name, Strings, Images);
H := FindNext(F);
end;
SysUtils.FindClose(F);
Result := Strings.Count > 0;
finally
Strings.EndUpdate;
end;
end;
{$ENDIF VCL}
{ imported from VCLFunctions }
procedure CenterHeight(const pc, pcParent: TControl);
begin
pc.Top := //pcParent.Top +
((pcParent.Height - pc.Height) div 2);
end;
function ToRightOf(const pc: TControl; piSpace: Integer): Integer;
begin
if pc <> nil then
Result := pc.Left + pc.Width + piSpace
else
Result := piSpace;
end;
{ compiled from ComCtrls.pas's implmentation section }
function HasFlag(A, B: Integer): Boolean;
begin
Result := (A and B) <> 0;
end;
function ConvertStates(const State: Integer): TItemStates;
begin
Result := [];
{$IFDEF VCL}
if HasFlag(State, LVIS_ACTIVATING) then
Include(Result, isActivating);
if HasFlag(State, LVIS_CUT) then
Include(Result, isCut);
if HasFlag(State, LVIS_DROPHILITED) then
Include(Result, isDropHilited);
if HasFlag(State, LVIS_FOCUSED) then
Include(Result, IsFocused);
if HasFlag(State, LVIS_SELECTED) then
Include(Result, isSelected);
{$ENDIF VCL}
end;
function ChangeHasSelect(const peOld, peNew: TItemStates): Boolean;
begin
Result := (not (isSelected in peOld)) and (isSelected in peNew);
end;
function ChangeHasDeselect(const peOld, peNew: TItemStates): Boolean;
begin
Result := (isSelected in peOld) and (not (isSelected in peNew));
end;
function ChangeHasFocus(const peOld, peNew: TItemStates): Boolean;
begin
Result := (not (IsFocused in peOld)) and (IsFocused in peNew);
end;
function ChangeHasDefocus(const peOld, peNew: TItemStates): Boolean;
begin
Result := (IsFocused in peOld) and (not (IsFocused in peNew));
end;
function GetListItemColumn(const pcItem: TListItem; piIndex: Integer): string;
begin
if pcItem = nil then
begin
Result := '';
Exit;
end;
if (piIndex < 0) or (piIndex > pcItem.SubItems.Count) then
begin
Result := '';
Exit;
end;
if piIndex = 0 then
Result := pcItem.Caption
else
Result := pcItem.SubItems[piIndex - 1];
end;
{from JvVCLUtils }
{ Bitmaps }
{$IFDEF VisualCLX}
type
TPrivateControl = class(TComponent)
protected
FVisible: Boolean;
end;
procedure CopyParentImage(Control: TControl; Dest: TCanvas);
var
Pixmap: QPixmapH;
DestDev: QPaintDeviceH;
pdm: QPaintDeviceMetricsH;
OrigVisible: Boolean;
begin
if (Control = nil) or (Control.Parent = nil) then
Exit;
Dest.Start;
try
DestDev := QPainter_device(Dest.Handle);
with Control.Parent do
ControlState := ControlState + [csPaintCopy];
try
pdm := QPaintDeviceMetrics_create(DestDev);
try
Pixmap := QPixmap_create(Control.Width, Control.Height,
QPaintDeviceMetrics_depth(pdm), QPixmapOptimization_DefaultOptim);
finally
QPaintDeviceMetrics_destroy(pdm);
end;
OrigVisible := TPrivateControl(Control).FVisible;
TPrivateControl(Control).FVisible := False; // do not draw the Control itself
try
QPixmap_grabWidget(Pixmap, Control.Parent.Handle, Control.Left,
Control.Top, Control.Width, Control.Height);
Qt.bitBlt(DestDev, 0, 0, Pixmap, 0, 0, Control.Width,
Control.Height, Qt.RasterOp_CopyROP, True);
finally
TPrivateControl(Control).FVisible := OrigVisible;
QPixmap_destroy(Pixmap);
end;
finally
with Control.Parent do
ControlState := ControlState - [csPaintCopy];
end;
finally
Dest.Stop;
end;
end;
{$ENDIF VisualCLX}
{$IFDEF VCL}
// see above for VisualCLX version of CopyParentImage
type
TJvParentControl = class(TWinControl);
procedure CopyParentImage(Control: TControl; Dest: TCanvas);
var
I, Count, X, Y, SaveIndex: Integer;
DC: HDC;
R, SelfR, CtlR: TRect;
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -