首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> Delphi

Delphi DDE 客戶端控制程序管理器:創建組、添加項目、刪除組實戰

     編輯:Delphi

7.3.9 利用客戶端程序控制程序管理器

程序管理器提供 DDE 接口命令字符串,應用程序可發送命令實現以下功能:

功能命令格式說明
創建程序組CreateGroup(組名[,路徑])不存在則創建,存在則按路徑激活
刪除程序組DeleteGroup(組名)
顯示程序組ShowGroup(組名,顯示標誌)控制極大/極小/正常顯示
重新裝入程序組ReLoadGroup(組名)先刪除後重新裝入
添加程序項AddItem(命令行[,描述[,圖標路徑[,圖標序號[,坐標[,工作目錄[,熱鍵[,最小化標誌]]]]]]])參數均有默認值,可選
替換程序項ReplaceItem(項目名)刪除並記錄位置,後續 AddItem 在該位置添加
刪除程序項DeleteItem(項目名)從當前活動組刪除
關閉程序管理器ExitProgram(保存標誌)

發送命令方法基本一致,例程簡化實現單字符串參數情況,易於擴展。

界面設計

包含 DDEClientConv 組件(設計時與程序管理器建立會話,服務/主題均為 PROGMAN,ConnectMode=ddeManual)及四功能按鈕。

核心 SendMacro 函數

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;
  1. Format 構造宏字符串:[Command(Name)] + 回車換行
  2. StrPCopy 轉為 PChar(程序管理器要求)
  3. 手動模式: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;
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved