📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, MotoP2KMode, StdCtrls, ComCtrls, MotoATMode, USBCtrls,
ShellAPI, ShlObj, ActiveX, ExtCtrls, MotoSysUtils;
type
TForm1 = class(TForm)
MotoP2KMode1: TMotoP2KMode;
GroupBox1: TGroupBox;
ListBox1: TListBox;
GroupBox3: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button6: TButton;
MotoATMode1: TMotoATMode;
GroupBox2: TGroupBox;
Button4: TButton;
CheckBox1: TCheckBox;
ListView1: TListView;
Label3: TLabel;
ProgressBar1: TProgressBar;
Button5: TButton;
ComboBox1: TComboBox;
SetActive: TButton;
Label4: TLabel;
Button7: TButton;
Button8: TButton;
Button9: TButton;
OpenDialog1: TOpenDialog;
Button10: TButton;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
CheckBox4: TCheckBox;
Edit1: TEdit;
RadioGroup1: TRadioGroup;
Button11: TButton;
Button12: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure MotoP2KMode1Arrival(Sender: TObject);
procedure MotoP2KMode1Remove(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure MotoATMode1Arrival(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure SetActiveClick(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
procedure ListView1Click(Sender: TObject);
procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
procedure RadioGroup1Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Load : boolean = false;
implementation
{$R *.dfm}
function ExtractFileName(const FileName: string): string;
var
I: Integer;
begin
I := LastDelimiter('/', FileName);
Result := Copy(FileName, I + 1, MaxInt);
end;
threadvar myDir: string;
function BrowseCallbackProc(hwnd: HWND; uMsg: UINT; lParam: LPARAM; lpData:LPARAM): integer; stdcall;
begin
Result := 0;
if uMsg = BFFM_INITIALIZED then begin
SendMessage(hwnd, BFFM_SETSELECTION, 1, LongInt(PChar(myDir)))
end;
end;
function SelectDirectory(const Caption: string; const Root: WideString; var Directory: string): Boolean;
var WindowList: Pointer;
BrowseInfo: TBrowseInfo;
Buffer: PChar;
RootItemIDList, ItemIDList: PItemIDList;
ShellMalloc: IMalloc;
IDesktopFolder: IShellFolder;
Eaten, Flags: LongWord;
begin
myDir := Directory;
Result := False;
FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);
if (ShGetMalloc(ShellMalloc) = S_OK) and (ShellMalloc <> nil) then begin
Buffer := ShellMalloc.Alloc(MAX_PATH);
try
RootItemIDList := nil;
if Root <> '' then begin
SHGetDesktopFolder(IDesktopFolder);
IDesktopFolder.ParseDisplayName(Application.Handle, nil,
POleStr(Root), Eaten, RootItemIDList, Flags);
end;
with BrowseInfo do begin
hwndOwner := Application.Handle;
pidlRoot := RootItemIDList;
pszDisplayName := Buffer;
lpfn := @BrowseCallbackProc;
lParam := Integer(PChar(Directory));
lpszTitle := PChar(Caption);
ulFlags := BIF_RETURNONLYFSDIRS or $0040 or BIF_EDITBOX or BIF_STATUSTEXT;
end;
WindowList := DisableTaskWindows(0);
try
ItemIDList := ShBrowseForFolder(BrowseInfo);
finally
EnableTaskWindows(WindowList);
end;
Result := ItemIDList <> nil;
if Result then begin
ShGetPathFromIDList(ItemIDList, Buffer);
ShellMalloc.Free(ItemIDList);
Directory := Buffer;
if Length(Directory)>0 then
if Directory[Length(Directory)]<>'\' then Directory := Directory + '\';
end;
finally
ShellMalloc.Free(Buffer);
end;
end;
end;
function Progress(AFile:TP2KFile):boolean;
begin
Result := true;
with Form1.ListView1.Items.Add do begin
Caption := IntToStr(Index+1);
SubItems.Text :=
Format('%S'+#13#10+'%S'+#13#10+'%d',[AFile.Name,FormatAttrP2KFileStr(AFile.Attr),AFile.Size]);
Form1.ProgressBar1.Position := Index;
end;
Form1.ProgressBar1.Perform(WM_Paint,0,0);
end;
procedure GetDevises;
var i : integer;
Dev : TMotoP2KModemItem;
begin
with Form1 do begin
ListBox1.Clear;
for i:=0 to MotoP2KMode1.DeviceList.Count-1 do begin
Dev := MotoP2KMode1.DeviceList.Items[i];
if Dev=nil then continue;
ListBox1.Items.Add(Dev.ModemInfo.DeviceDescr);
end;
if ListBox1.Items.Count>0 then
ListBox1.ItemIndex := 0;
ListBox1.OnClick(nil);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.DoubleBuffered := true;
Constraints.MinHeight := Height;
Constraints.MaxHeight := Height;
Constraints.MinWidth := Width;
Constraints.MaxWidth := Width;
GetDevises;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
GetDevises;
end;
procedure TForm1.ListBox1Click(Sender: TObject);
var item : TMotoP2KModemItem;
begin
Label2.Caption := 'DisConnect';
if (ListBox1.ItemIndex<0) and (ListBox1.ItemIndex>=ListBox1.Count) then exit;
// Get
item := MotoP2KMode1.DeviceList.Items[ListBox1.ItemIndex];
if item=nil then exit;
// Status
if item.IsOpened then
Label2.Caption := 'Connect'
else
Label2.Caption := 'DisConnect';
//
case item.FSACOptions of
fsacBP : RadioGroup1.ItemIndex := 0;
fsacAP : RadioGroup1.ItemIndex := 1;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var item : TMotoP2KModemItem;
begin
if (ListBox1.ItemIndex<0) and (ListBox1.ItemIndex>=ListBox1.Count) then exit;
item := MotoP2KMode1.DeviceList.Items[ListBox1.ItemIndex];
if item=nil then exit;
item.Open;
ListBox1.OnClick(nil);
end;
procedure TForm1.Button3Click(Sender: TObject);
var item : TMotoP2KModemItem;
begin
if (ListBox1.ItemIndex<0) and (ListBox1.ItemIndex>=ListBox1.Count) then exit;
item := MotoP2KMode1.DeviceList.Items[ListBox1.ItemIndex];
if item=nil then exit;
item.Close;
ListBox1.OnClick(nil);
end;
procedure TForm1.MotoP2KMode1Arrival(Sender: TObject);
begin
GetDevises;
end;
procedure TForm1.MotoP2KMode1Remove(Sender: TObject);
begin
GetDevises;
end;
procedure TForm1.Button6Click(Sender: TObject);
var i:integer;
s:string;
begin
if MotoATMode1.DeviceList.Count<1 then begin
ShowMEssage('玉蝠铋耱忄 礤 磬殇屙
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -