Delphi 註冊 關聯 指定的副檔名

2021-06-09 23:12:59 字數 1623 閱讀 4114

(*

註冊(關聯)指定的副檔名

*)unit xregext;

inte***ce

uses

registry, shlobj, windows;

/// /// 獲取指定副檔名的開啟程式

///

function getexebyextension(***t : string) : string;

/// /// 註冊(關聯)指定的副檔名

///

/// 副檔名(不含".")

implementation

function getexebyextension(***t : string) : string;

var ***tdesc:string;

begin

with tregistry.create do

begin

tryrootkey:=hkey_classes_root;

if openkeyreadonly(***t) then

begin

***tdesc:=readstring('') ;

closekey;

end;

if ***tdesc <>'' then

begin

if openkeyreadonly(***tdesc + '/shell/open/command') then

begin

result:= readstring('') ;

endend;

finally

free;

end;

end;

if result <> '' then

begin

if result[1] = '"' then

begin

result:=copy(result,2,-1 + pos('"',copy(result,2,maxint))) ;

endend;

end;

var reg:tregistry;

begin

reg := tregistry.create;

tryreg.rootkey:=hkey_classes_root;

reg.openkey('.' + extname, true) ;

reg.writestring('', extname + 'file') ;

reg.closekey;

reg.createkey(extname + 'file') ;

reg.openkey(extname + 'file\defaulticon', true) ;

reg.closekey;

reg.openkey(extname + 'file\shell\open\command', true) ;

reg.closekey;

finally

reg.free;

end;

shchangenotify(shcne_assocchanged, shcnf_idlist, nil, nil) ;

end;

end.

用法: 

// 註冊副檔名

Delphi全域性熱鍵的註冊

1.在窗啟動時建立atom aatom atom 定義在private中 1 if findatom zwxhotkey 0 then 2begin 3 aatom globaladdatom zwxhotkey 4end 5 if registerhotkey handle,aatom,mod a...

uvm中關聯陣列的註冊

在編寫uvm驗證環境時,xaction中時常會使用到關聯陣列.為了方便copy compare,會使用uvm field aa 相關的巨集定義來完成註冊.1.巨集定義簡介 聯合陣列有兩大識別標誌,一是索引的型別,二是儲存資料的型別.在巨集定義中第乙個出現的型別是儲存資料的型別,第二個是索引型別.例如...

隱藏指定的副檔名

我們都知道在windows系統下有個資料夾選項,可以將已知的副檔名顯示或者隱藏起來。但這裡的顯示已知檔案的副檔名,未必能夠真正的顯示所有已知檔案型別的副檔名,比如說,批處理的快捷方式副檔名是.pif,ie頁面的快捷方式是.url,這樣的副檔名真的是很罕見,但是他們卻一直存在,不過他們的副檔名真實面貌...