程序管理器提供 DDE 接口命令字符串,應用程序可發送命令實現以下功能:
| 功能 | 命令格式 | 說明 |
|---|---|---|
| 創建程序組 | CreateGroup(組名[,路徑]) | 不存在則創建,存在則按路徑激活 |
| 刪除程序組 | DeleteGroup(組名) | |
| 顯示程序組 | ShowGroup(組名,顯示標誌) | 控制極大/極小/正常顯示 |
| 重新裝入程序組 | ReLoadGroup(組名) | 先刪除後重新裝入 |
| 添加程序項 | AddItem(命令行[,描述[,圖標路徑[,圖標序號[,坐標[,工作目錄[,熱鍵[,最小化標誌]]]]]]]) | 參數均有默認值,可選 |
| 替換程序項 | ReplaceItem(項目名) | 刪除並記錄位置,後續 AddItem 在該位置添加 |
| 刪除程序項 | DeleteItem(項目名) | 從當前活動組刪除 |
| 關閉程序管理器 | ExitProgram(保存標誌) |
發送命令方法基本一致,例程簡化實現單字符串參數情況,易於擴展。
包含 DDEClientConv 組件(設計時與程序管理器建立會話,服務/主題均為 PROGMAN,ConnectMode=ddeManual)及四功能按鈕。
function TForm1.SendMacro(Name: String; Command: String): Boolean;
var Macro: String; Cmd: array[0..255] of Char;
begin
Result := True;
if Name <> '' then
begin
Macro := Format('['+Command+'(%s)]', [Name]) + #13#10;
StrPCopy(Cmd, Macro);
DDEClient.OpenLink;
if not DDEClient.ExecuteMacro(Cmd, False) then Result := False;
DDEClient.CloseLink;
end;
end;
Format 構造宏字符串:[Command(Name)] + 回車換行StrPCopy 轉為 PChar(程序管理器要求)OpenLink → ExecuteMacro(失敗返回 False)→ CloseLink// 創建程序組
procedure TForm1.CreateButtonClick(Sender: TObject);
var Name: String;
begin
Name := InputBox('Input Box','Input Group Name','');
if Name = '' then MessageDlg('Group name can not be blank.', mtError, [mbOK], 0)
else if not SendMacro(Name,'CreateGroup') then MessageDlg('Unable to create group.', mtInformation, [mbOK], 0);
end;
// 添加程序項
procedure TForm1.AddButtonClick(Sender: TObject);
var Name: String;
begin
Name := InputBox('Input Box','Input Application full_Path name','');
if Name = '' then MessageDlg('Application name can not be blank.', mtError, [mbOK], 0)
else if not SendMacro(Name,'AddItem') then MessageDlg('Unable to Add Item.', mtInformation, [mbOK], 0);
end;
// 刪除程序組
procedure TForm1.DeleteButtonClick(Sender: TObject);
var Name: String;
begin
Name := InputBox('Input Box','Input Group Name to be Deleted','');
if Name = '' then MessageDlg('Group name can not be blank.', mtError, [mbOK], 0)
else if not SendMacro(Name,'DeleteGroup') then MessageDlg('Unable to create group.', mtInformation, [mbOK], 0);
end;