我修改了DDHCode的一个例子,运行良好.
kxy@csdn.net 来信我发过去.
function TContextMenu.BuildSubMenu( Menu: HMENU;
IndexMenu: Integer;
var IDCmdFirst: Integer ): HMENU;
var
i: Integer;
menuItemInfo: TMenuItemInfo;
TempMenu : HMENU;
begin
if Menu = 0 then
Result := CreateMenu
else
Result := Menu;
// Build the menu items here
with menuitemInfodo
begin
cbSize := SizeOf( TMenuItemInfo );
fMask := MIIM_CHECKMARKS or MIIM_DATA or MIIM_ID or
MIIM_STATE or MIIM_SUBMENU or MIIM_TYPE;
fType := MFT_STRING;
fState := MFS_ENABLED;
hSubMenu := 0;
hbmpChecked := 0;
hbmpUnchecked := 0;
end;
for i := 0 to High( MenuCommandStrings )do
begin
menuitemInfo.dwTypeData := PChar(MenuCommandStrings[ i ]);
menuitemInfo.wID := IDCmdFirst;
InsertMenuItem( Result, IndexMenu + i, True, menuItemInfo );
Inc( IDCmdFirst );
end;
{康新勇添加}
menuitemInfo.dwTypeData := 'Test SubMenu';
menuitemInfo.wID := IDCmdFirst;
menuitemInfo.hSubMenu := CreatePopupMenu;
TempMenu := menuitemInfo.hSubMenu;
InsertMenuItem( Result , IndexMenu + i, True, menuItemInfo );
Inc( IDCmdFirst );
menuitemInfo.dwTypeData := 'Open Notpad';
menuitemInfo.wID := IDCmdFirst;
menuIteminfo.hSubMenu := 0;
InsertMenuItem( TempMenu, IndexMenu + i, True, menuItemInfo );
Inc( IDCmdFirst );
{ menuitemInfo.dwTypeData := 'Open Nodpad';
menuitemInfo.wID := IDCmdFirst;}
end;
function TContextMenu.InvokeCommand( var lpici:
TCMInvokeCommandInfo ): HResult;
var
idCmd: UINT;
begin
if HIWORD( Integer(lpici.lpVerb) ) <> 0 then
Result := E_FAIL
else
begin
idCmd := LOWORD( lpici.lpVerb );
Result := S_OK;
case idCmd of
0:
ShellExecute( GetDesktopWindow, nil, SW_PATH,
PChar('"' + FFileName + '"'), nil, SW_SHOW );
1:
ShellExecute( GetDesktopWindow, nil, SW_PATH,
PChar('/P "' + FFileName + '"'), nil, SW_SHOW );
3 : ShowMessage('OK');
// 康新勇
else
Result := E_FAIL;
end;
end;
end;