📄 func.pas
字号:
unit func;
interface
uses
Sysutils, Windows, Controls, Registry, Inifiles, Forms;
function MyPath:String;
function DirectoryExists(const Name: String): Boolean;
procedure AssocExeDllFile(Add_Del:Boolean);
implementation
function MyPath:String;
begin
Result:=ExtractFilePath(ParamStr(0));
if Result[Length(Result)]<>'\' then
Result:=Result+'\';
end;
function DirectoryExists(const Name: String): Boolean;
var
Code: Integer;
begin
Code := GetFileAttributes(PChar(Name));
Result := (Code <> -1) and (FILE_ATTRIBUTE_DIRECTORY and Code <> 0);
end;
procedure AssocExeDllFile(Add_Del:Boolean);
var
Reg:TRegistry;
Key1,Key2:String;
begin
Reg:=TRegistry.Create;
try
Reg.RootKey:=HKEY_CLASSES_ROOT;
Key1:='\exefile\Shell\用 PEDUMP 分析';
Key2:='\dllfile\Shell\用 PEDUMP 分析';
if Add_Del then
begin{Add}
Reg.OpenKey(Key1+'\Command',True);
Reg.WriteString('',Application.ExeName+' "%1"');
Reg.OpenKey(Key2+'\Command',True);
Reg.WriteString('',Application.ExeName+' "%1"');
end else
begin{Delete}
Reg.OpenKey(Key1+'\Command',True);
Reg.DeleteKey(Key1);
Reg.OpenKey(Key2+'\Command',True);
Reg.DeleteKey(Key2);
end;
Reg.CloseKey;
finally
Reg.Free;
end;
end;
procedure SetWinPos(WinForm:TForm);
var
StrPos,StrScr:String;
begin
{left,top,width,height}
StrPos:=Format('%d,%d,%d,%d',[WinForm.Left,WinForm.Top,WinForm.Width,WinForm.Height]);
StrScr:=Format('WinPos(%d,%d)',[Screen.Width,Screen.Height]);
with TInifile.Create(MyPath+'pedump.ini') do
begin
WriteString('pedump',StrScr,StrPos);
end;
end;
procedure GetWinPos(WinForm:TForm);
const
SEP=',';
var
i:Integer;
StrPos,StrScr:String;
begin
StrScr:=Format('WinPos(%d,%d)',[Screen.Width,Screen.Height]);
with TInifile.Create(MyPath+'pedump.ini') do
begin
StrPos:=ReadString('pedump',StrScr,'0,0,0,0');
end;
{left}
i:=Pos(SEP,StrPos);
// if i=0 then raise Error;
WinForm.Left:=StrToInt(Copy(StrPos,1,i-1));
Delete(StrPos,1,i);
{top}
i:=Pos(SEP,StrPos);
WinForm.Top:=StrToInt(Copy(StrPos,1,i-1));
Delete(StrPos,1,i);
{width}
i:=Pos(SEP,StrPos);
WinForm.Width:=StrToInt(Copy(StrPos,1,i-1));
Delete(StrPos,1,i);
{height}
WinForm.Height:=StrToInt(StrPos);
end;
procedure Magnetize(var IntLeft,IntTop:Integer;MagForm:TForm;HWnd_Custrom:HWND);
const
{ magnetize effect }
MagneticForce:integer=10;
var
HWnd_Tray,HWnd_Explorer:HWND;
RWnd_Tray,RWnd_Explorer,RWnd_Custrom:TRect;
begin
if HWnd_Custrom>0 then
begin
{ get custom rect }
GetWindowRect(HWnd_Custrom, RWnd_Custrom);
{ mangetize custrom}
if Abs(RWnd_Custrom.Bottom-IntTop)<MagneticForce then IntTop:=RWnd_Custrom.Bottom
else if Abs(IntTop+MagForm.Height-RWnd_Custrom.Top)<MagneticForce then IntTop:=RWnd_Custrom.Top-MagForm.Height;
if Abs(RWnd_Custrom.Right-IntLeft)<MagneticForce then IntLeft:=RWnd_Custrom.Right
else if Abs(IntLeft+MagForm.Width-RWnd_Custrom.Left)<MagneticForce then IntLeft:=RWnd_Custrom.Left-MagForm.Width;
end;
HWnd_Explorer:=FindWindow('CabinetWClass',nil);
if HWnd_Explorer>0 then
begin
{ get explorer rect }
GetWindowRect(HWnd_Explorer, RWnd_Explorer);
{ mangetize explorer}
if Abs(RWnd_Explorer.Bottom-IntTop)<MagneticForce then IntTop:=RWnd_Explorer.Bottom
else if Abs(IntTop+MagForm.Height-RWnd_Explorer.Top)<MagneticForce then IntTop:=RWnd_Explorer.Top-MagForm.Height;
if Abs(RWnd_Explorer.Right-IntLeft)<MagneticForce then IntLeft:=RWnd_Explorer.Right
else if Abs(IntLeft+MagForm.Width-RWnd_Explorer.Left)<MagneticForce then IntLeft:=RWnd_Explorer.Left-MagForm.Width;
end;
HWnd_Tray:=FindWindow('Shell_TrayWnd',nil);
if HWnd_Tray>0 then
begin
{ get taskbar rect }
GetWindowRect(HWnd_Tray, RWnd_Tray);
{ mangetize tray}
if Abs(RWnd_Tray.Bottom-IntTop)<MagneticForce then IntTop:=RWnd_Tray.Bottom
else if Abs(IntTop+MagForm.Height-RWnd_Tray.Top)<MagneticForce then IntTop:=RWnd_Tray.Top-MagForm.Height;
if Abs(RWnd_Tray.Right-IntLeft)<MagneticForce then IntLeft:=RWnd_Tray.Right
else if Abs(IntLeft+MagForm.Width-RWnd_Tray.Left)<MagneticForce then IntLeft:=RWnd_Tray.Left-MagForm.Width;
end;
{ magnetize screen }
if IntLeft<MagneticForce then IntLeft:=0;
if IntLeft>Screen.Width-MagForm.Width-MagneticForce then IntLeft:=Screen.Width-MagForm.Width;
if IntTop<MagneticForce then IntTop:=0;
if IntTop>Screen.Height-MagForm.Height-MagneticForce then IntTop:=Screen.Height-MagForm.Height;
{ end screen }
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -