當用戶在資源管理器中調用右鍵菜單時
屬性頁擴展通常是同某類文件相關聯的來實現同之相關的操作和信息顯示
一
首先
同文件建立關聯需要注冊屬性頁
type
TCXPropSheetFactory=class(TComObjectFactory)
public
procedure UpdateRegistry(Register: Boolean); override;
end;
procedure TCXPropSheetFactory
ClassID: string;
Str
inherited UpdateRegistry(Register);
if Register then
begin
ClassID:=GUIDToString(Class_CXPropSheet);
with TRegistry
try
RootKey:=HKEY_CLASSES_ROOT;
OpenKey(
KeyName := ReadString(
if Keyname =
begin
WriteString(
OpenKey(
KeyName := ReadString(
end;
OpenKey(
WriteString(
finally
Free;
end;
if(Win
begin
with TRegistry
try
RootKey:=HKEY_LOCAL_MACHINE;
OpenKey(
OpenKey(
WriteString(ClassID
finally
Free;
end;
end;
end
else
刪除注冊表項
function TCXPropSheet
lpdobj: IDataObject; hKeyProgID: HKEY): HResult;
var
StgMedium: TStgMedium;
FormatEtc: TFormatEtc;
szFile: array[
filecount: integer;begin
Result:=E_FAIL;
if(lpdobj=nil)then
begin
Result:=E_INVALIDARG;
messagebox(
Exit;
end;
with FormatEtc do
begin
cfFormat:=CF_HDROP;
ptd:=nil;
dwAspect:=DVASPECT_CONTENT;
lindex:=
tymed:=TYMED_HGLOBAL;
end;
Result:=lpdobj
if Failed(Result)then
Exit;
//如果只有一個文件被選中
filecount:=DragQueryFile(stgmedium
if filecount=
begin
Result:=NOERROR;
DragQueryFile(stgmedium
FFilename:=strpas(szFile);
end;
ReleaseStgMedium(StgMedium);end;添加頁面的操作是通過IShellPropSheetExt接口來實現的
IShellPropSheetExt
一般的IShellPropSheetExt
· 給PROPSHEETPAGE結構設定正確的值
· 實現PropSheetPageProc回調函數來處理頁面創建和銷毀的情況
· 調用CreatePropertySheetPage函數來創建頁面
· 調用lpfnAddPage指向的函數來來添加創建好的頁面
function TCXPropSheet
lParam: LPARAM): HResult;var
PSP: TPropSheetPage;
HPSP: HPropSheetPage;begin
result:=E_FAIL;
try
psp
psp
psp
//這裡我們使用了事先儲存在wave
//resource workshop編輯的
psp
//標題名
psp
//設定回調函數
psp
psp
//設定對象引用記數變量
psp
//用lParam向回調函數傳遞對象
psp
HPSP:=CreatePropertySheetPage(psp);
if HPSP$#@
if not lpfnAddPage(HPSP
DestroyPropertySheetPage(HPSP);
end else begin
_addref;//增加引用記數
result:=S_OK;
end
end
except
on e: exception do begin
e
messagebox(
end;
end;end;
function TCXPropSheet
lpfnReplaceWith: TFNADDPROPSHEETPAGE; lParam: LPARAM): HResult;begin
Result:=E_NOTIMPL;//同文件關聯時
function DialogProc(hwndDlg: HWnd; Msg: UINT; wParam: wParam;
lParam: LPARAM): Bool; stdcall;
var
PageObj: TCXPropSheet;
filename: string;
displayName : string;
SheetHWnd: HWnd;
begin
result:=false;
try
if Msg=WM_INITDIALOG then begin//初始化界面
//獲得lparam傳遞過來的對象
pageObj:=TCXPropSheet(PPropSheetPage(lParam)^
//保存對象信息
SetWindowLong(hwndDlg
//設置界面顯示波文件信息
SetDlgItemText(hwndDlg
OpenMedia(PageObj
SetDlgItemText(hwndDlg
SetDlgItemText(hwndDlg
SetDlgItemText(hwndDlg
CloseMedia;
SetWindowLong(hwndDlg
Result:=TRUE;
end
else if(Msg=WM_COMMAND)then begin
if Lo(wParam)=
MessageBox(
end else if(msg=WM_NOTIFY)then begin
sheetHwnd:=getparent(hwndDlg);//獲得屬性頁的窗口句柄
case PNMHdr(lparam)^
//頁面失去焦點
PSN_KILLACTIVE:
begin
SetWindowLong(hwndDlg
Result:=TRUE;
end;
end;
end;
except
on e: exception do begin
e
messagebox(
end;
end;
end;
二
同上面講的有兩點不同
IShellExtInit
注冊表項是HKEY_CLASSES_ROOT\Drive\Shellex\PropertySheetHandlers子鍵
三
同上面講的有兩點不同
控制面板程序調用IShellPropSheetExt
注冊方式
From:http://tw.wingwit.com/Article/program/Delphi/201311/25066.html