📄 umainform2.pas
字号:
unit uMainForm2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, bsSkinData, bsSkinCtrls, BusinessSkinForm, ImgList,
uAsciiConstructorForm, uCommentConstructorForm, uCustomModuleForm,
uKeyValueModuleForm, uMessageBoxConstructorForm, uSendEmaiConstructorForm,
xuFunctionModuleForm, uAccessModuleForm, ShellAPI, Types, MMSystem,
IniFiles, uFunctionbaseModuleForm, uApiModuleForm, uPasFileEditForm,
StdCtrls, AWTrayIcon, uResBuilder, uhelp, registry;
type
TButtonInfo = class(TPersistent)
public
Section: integer;
ButtonName: string;
FileName: string;
Params: string;
Button: TbsButtonBarItem;
end;
TfmMain = class(TForm)
skinButtonsBar: TbsSkinButtonsBar;
skinData: TbsSkinData;
skinStoredSkin: TbsStoredSkin;
skinForm: TbsBusinessSkinForm;
ilButtons: TImageList;
tmHide: TTimer;
tmtime: TTimer;
pnlAddButtons: TbsSkinPanel;
btnAdd: TbsSkinSpeedButton;
btnModify: TbsSkinSpeedButton;
AWTrayIcon1: TAWTrayIcon;
procedure bsSkinButtonsBar1Sections0Items0Click(Sender: TObject);
procedure bsSkinButtonsBar1Sections0Items1Click(Sender: TObject);
procedure bsSkinButtonsBar1Sections0Items2Click(Sender: TObject);
procedure bsSkinButtonsBar1Sections0Items3Click(Sender: TObject);
procedure bsSkinButtonsBar1Sections0Items4Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure skinButtonsBarSections2Items0Click(Sender: TObject);
procedure skinButtonsBarSections1Items0Click(Sender: TObject);
procedure tmHideTimer(Sender: TObject);
procedure skinButtonsBarMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
procedure tmtimeTimer(Sender: TObject);
procedure skinButtonsBarSections2Items1Click(Sender: TObject);
procedure SectionsSoundClick(Sender: TObject);
procedure btnAddClick(Sender: TObject);
procedure btnModifyClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure skinButtonsBarSections1Items1Click(Sender: TObject);
procedure skinButtonsBarSections1Items2Click(Sender: TObject);
procedure skinButtonsBarSections2Items2Click(Sender: TObject);
procedure skinButtonsBarSections2Items3Click(Sender: TObject);
procedure AWTrayIcon1LeftClick(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure skinButtonsBarSections2Items4Click(Sender: TObject);
private
{ Private declarations }
FSendEmailDialog: TSendEmailDialog;
FMessageBoxDialog: TMessageBoxDialog;
FKeyValueDialog: TKeyValueDialog;
FAsciiDialog: TAsciiDialog;
FCommentDialog: TCommentDialog;
FFunctionDialog: TFunctionDialog;
FAccessDialog: TAccessDialog;
FResBuilderDialog: TResBuilderDialog;
FApiDialog: TApiDialog;
FFunctionbaseDialog: TFunctionbaseDialog;
FHelpDialog: THelpDialog;
FPlaySound: boolean;
FMode: integer;
FHidetimen, Ftop, Fleft: integer;
FCanHide, FIsMoveing: boolean;
FUserButtonsIniFile: TIniFile;
FPanelCount: integer;
procedure ShowSendEmailDialog;
procedure ShowHelpDialog;
procedure ShowMessageBoxDialog;
procedure ShowKeyValueDialog;
procedure ShowAsciiDialog;
procedure ShowCommentDialog;
procedure ShowCalc;
procedure ShowFunctionDialog;
procedure ShowApiDialog;
procedure ShowFunctionbaseDialog;
procedure ShowAccessDialog;
procedure ShowResBuilderDialog;
procedure SetForm;
procedure HideForm;
procedure WMMOVE(var Msg: TMessage); message WM_MOVE;
procedure WMMOUSEWHEEL(var Msg: TMessage); message WM_MOUSEWHEEL;
procedure ActiveWindow(const HWnd: HWND);
function IsMouseInForm: Boolean;
procedure OnUserButtonClick(Sender: TObject);
procedure OnUserPanelClick(Sender: TObject);
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure EnableChanged(var Msg: TWMEnable); message WM_ENABLE;
public
{ Public declarations }
FUserButtonsList: TStringList;
function AddImageToImageList(const AFile: string): Integer;
procedure PlayButtonBarButtonClickSound;
procedure PlayDefButtonClickSound;
procedure SetMode(const Mode: integer);
procedure SetSound(const PlaySound: Boolean);
function AddToolButton(const AButtonName, AFile, AParams: string; const ASection: integer): Boolean;
procedure ModifyButton(const AButtonName, AFile, AParams: string; const ASection: integer);
procedure DeleteToolButton(const Index: Integer; const AButtonName: string);
procedure LoadUserButtons;
procedure LoadUserPanel;
procedure ModifyUserPanel(const aPanelName: string; const aSection: integer);
procedure AddUserPanel(const aPanelName: string);
procedure DeleteUserPanel(const aPanelName: string; const aSection: integer);
end;
var
fmMain: TfmMain;
implementation
uses uAddButton, uModifyButton;
{$R SOUND.RES} // 引入资源声音
{$R *.dfm}
procedure TfmMain.SetMode(const Mode: integer);
begin
FMode := Mode;
FUserButtonsIniFile.WriteInteger('Set', 'Mode', Mode);
end;
procedure TfmMain.SetSound(const PlaySound: Boolean);
begin
FPlaySound := PlaySound;
FUserButtonsIniFile.WriteBool('Set', 'Sound', PlaySound);
end;
procedure TfmMain.HideForm;
begin
FCanHide := true;
tmHide.Enabled := true;
FHidetimen := 0;
tmtime.Enabled := false;
end;
procedure TfmMain.SetForm;
begin
with fmMain do
begin
Width := FUserButtonsIniFile.ReadInteger('Set', 'Width', 60);
Height := FUserButtonsIniFile.ReadInteger('Set', 'Height', 540);
FPlaySound := FUserButtonsIniFile.ReadBool('Set', 'Sound', true);
FMode := FUserButtonsIniFile.Readinteger('Set', 'mode', 0);
skinButtonsBar.SectionIndex := FUserButtonsIniFile.ReadInteger('Set', 'Page', 0);
Left := Screen.Width - Width;
top := round((Screen.DesktopHeight - Height) / 2);
end;
end;
procedure TfmMain.WMMOVE(var Msg: TMessage);
var
p: tpoint;
begin
inherited;
if FCanHide and (not FIsMoveing) then
begin
GetCursorPos(p);
if (screen.Width - p.X < 20) and (fmMain.Height <> 25) then
begin
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
tmHide.Enabled := true;
end;
end;
end;
procedure TfmMain.FormCreate(Sender: TObject);
var
reg: Tregistry;
begin
FIsMoveing := false;
FCanHide := true;
FHidetimen := 2;
FUserButtonsIniFile := TIniFile.Create(ExtractFilePath(ParamStr(0)) +
'Buttons.ini');
reg := TRegistry.Create;
reg.RootKey := HKEY_CURRENT_USER;
reg.OpenKey('Software\AWINSoft', true);
reg.WriteString('Delphi函数工厂', ParamStr(0));
reg.Free;
FUserButtonsList := TStringList.Create;
SetForm;
Ftop := fmMain.Top;
Fleft := fmMain.Left;
// 加载用户自定义的按钮
LoadUserPanel;
LoadUserButtons;
AWTrayIcon1.Active := true;
AWTrayIcon1.Icon := application.Icon;
end;
procedure TfmMain.FormDestroy(Sender: TObject);
var
I: Integer;
begin
AWTrayIcon1.Active := false;
FUserButtonsIniFile.WriteInteger('Set', 'Page', skinButtonsBar.SectionIndex);
FUserButtonsIniFile.Free;
for I := 0 to FUserButtonsList.Count - 1 do
FUserButtonsList.Objects[I].Free;
FUserButtonsList.Free;
end;
procedure TfmMain.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle or WS_EX_TOPMOST or WS_EX_TOOLWINDOW
or WS_EX_DLGMODALFRAME;
Params.WndParent := 0;
SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW);
end;
procedure TfmMain.EnableChanged(var Msg: TWMEnable);
begin
EnableWindow(Handle, True);
inherited;
end;
procedure TfmMain.ShowSendEmailDialog;
begin
if not Assigned(FSendEmailDialog) then
begin
FSendEmailDialog := TSendEmailDialog.Create(Application);
try
FSendEmailDialog.Execute;
finally
FreeAndNil(FSendEmailDialog);
end;
end
else
ActiveWindow(FSendEmailDialog.Handle);
end;
procedure TfmMain.ShowHelpDialog;
begin
if not Assigned(FHelpDialog) then
begin
FHelpDialog := THelpDialog.Create(Application);
try
FHelpDialog.Execute;
finally
FreeAndNil(FHelpDialog);
end;
end
else
ActiveWindow(FHelpDialog.Handle);
end;
procedure TfmMain.ShowMessageBoxDialog;
begin
if not Assigned(FMessageBoxDialog) then
begin
FMessageBoxDialog := TMessageBoxDialog.Create(Application);
try
FMessageBoxDialog.Execute;
finally
FreeAndNil(FMessageBoxDialog);
end;
end
else
ActiveWindow(FMessageBoxDialog.Handle);
end;
procedure TfmMain.ShowKeyValueDialog;
begin
if not Assigned(FKeyValueDialog) then
begin
FKeyValueDialog := TKeyValueDialog.Create(Application);
try
FKeyValueDialog.Execute;
finally
FreeAndNil(FKeyValueDialog);
end;
end
else
ActiveWindow(FKeyValueDialog.Handle);
end;
procedure TfmMain.ShowAsciiDialog;
begin
if not Assigned(FAsciiDialog) then
begin
FAsciiDialog := TAsciiDialog.Create(Application);
try
FAsciiDialog.Execute;
finally
FreeAndNil(FAsciiDialog);
end;
end
else
ActiveWindow(FAsciiDialog.Handle);
end;
procedure TfmMain.ShowCommentDialog;
begin
if not Assigned(FCommentDialog) then
begin
FCommentDialog := TCommentDialog.Create(Application);
try
FCommentDialog.Execute;
finally
FreeAndNil(FCommentDialog);
end;
end
else
ActiveWindow(FCommentDialog.Handle);
end;
procedure TfmMain.ShowCalc;
var
FCalcHandle: HWND;
begin
FCalcHandle := FindWindow(nil, '计算器');
if FCalcHandle = 0 then
begin
if ShellExecute(Handle, 'OPEN', 'calc.exe', nil, nil, SW_SHOWNORMAL) <= 32 then
MessageBox(Handle, PChar('无法打开“计算器”!'), PChar('错误'),
MB_ICONERROR or MB_TOPMOST);
end
else
ActiveWindow(FCalcHandle);
end;
procedure TfmMain.ShowResBuilderDialog;
begin
if not Assigned(FResBuilderDialog) then
begin
FResBuilderDialog := TResBuilderDialog.Create(Application);
try
FResBuilderDialog.Execute;
finally
FreeAndNil(FResBuilderDialog);
end;
end
else
ActiveWindow(FResBuilderDialog.Handle);
end;
procedure TfmMain.ShowAccessDialog;
begin
if not Assigned(FAccessDialog) then
begin
FAccessDialog := TAccessDialog.Create(Application);
try
FAccessDialog.Execute;
finally
FreeAndNil(FAccessDialog);
end;
end
else
ActiveWindow(FAccessDialog.Handle);
end;
procedure TfmMain.ShowApiDialog;
begin
if not Assigned(FApiDialog) then
begin
FApiDialog := TApiDialog.Create(Application);
try
FApiDialog.Execute;
finally
FreeAndNil(FApiDialog);
end;
end
else
ActiveWindow(FApiDialog.Handle);
end;
procedure TfmMain.ShowFunctionbaseDialog;
begin
if not Assigned(FFunctionbaseDialog) then
begin
FFunctionbaseDialog := TFunctionbaseDialog.Create(Application);
try
FFunctionbaseDialog.Execute;
finally
FreeAndNil(FFunctionbaseDialog);
end;
end
else
ActiveWindow(FFunctionbaseDialog.Handle);
end;
procedure TfmMain.ShowFunctionDialog;
begin
if not Assigned(FFunctionDialog) then
begin
FFunctionDialog := TFunctionDialog.Create(Application);
try
FFunctionDialog.Execute;
finally
FreeAndNil(FFunctionDialog);
end;
end
else
ActiveWindow(FFunctionDialog.Handle);
end;
procedure TfmMain.ActiveWindow(const HWnd: HWND);
begin
if IsIconic(HWnd) then
ShowWindow(HWnd, SW_RESTORE);
SetForegroundWindow(HWnd);
end;
function TfmMain.IsMouseInForm: Boolean;
var
MousePoint: TPoint;
FormRect: TRect;
begin
GetCursorPos(MousePoint);
GetWindowRect(Handle, FormRect);
Result := Types.PtInRect(FormRect, MousePoint);
end;
procedure TfmMain.PlayButtonBarButtonClickSound;
begin
if FPlaySound then
PlaySound('BCLICK', hInstance, SND_ASYNC or SND_RESOURCE
or SND_NODEFAULT);
end;
procedure TfmMain.PlayDefButtonClickSound;
begin
if FPlaySound then
PlaySound('CLICK', hInstance, SND_ASYNC or SND_RESOURCE
or SND_NODEFAULT);
end;
procedure TfmMain.OnUserPanelClick(Sender: TObject);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -