2

在 Windows 8 上,我尝试运行下面显示的代码以显示旧的 Windows 7 图片查看器,但它返回错误。在 Windows 8 上,我可以找到 C:\Program Files (x86)\Windows Photo Viewer\PhotoViewer.dll 但我认为这是较新的 Windows 8 Metro 应用程序。我认为较旧的 Windows 图片查看器是 'c:\windows\system32\shimgvw.dll。我想用桌面应用程序样式而不是 Metro 预览图像。

我都试过了,但都返回该文件没有与之关联的程序?我在搞砸什么?

var
SEInfo: TShellExecuteInfo;
ExitCode: DWORD;
ExecuteFile, ParamString, StartInString: string;

ExecuteFile:='c:\windows\system32\shimgvw.dll';
FillChar(SEInfo, SizeOf(SEInfo), 0) ;
SEInfo.cbSize := SizeOf(TShellExecuteInfo);
with SEInfo do begin
  fMask := SEE_MASK_NOCLOSEPROCESS;
  Wnd := Application.Handle;
  lpFile := PChar(ExecuteFile);
  nShow := SW_SHOWNORMAL;
  lpParameters := PChar('ImageView_Fullscreen');
end;
if ShellExecuteEx(@SEInfo) then begin
repeat
   Application.ProcessMessages;
   GetExitCodeProcess(SEInfo.hProcess, ExitCode) ;
 until (ExitCode <> STILL_ACTIVE) or Application.Terminated;
   ShowMessage('Windows Picture Viewer terminated') ;
 end
    else ShowMessage('Error starting Windows Picture Viewer') ;

我之前没有使用过 ShellExecuteEx,所以代码的基础来自这里

4

1 回答 1

6

shimgvw.dll是一个DLL。您不能直接运行 DLL,您必须加载 DLL 并在其中调用导出的函数。

如果您查看 Windows 7 系统上的注册表,您将看到资源管理器调用照片查看器的操作:

%SystemRoot%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %1

rundll32.exe是 Windows 附带的一个工具,其存在纯粹是为了加载一个 DLL 并在其中调用一个函数。因此,您可以利用rundll32.exe来执行此操作,或者使用 加载 DLL LoadLibrary(),找到函数导出GetProcAddress()并自己调用该函数。

(还要注意,在 Windows 7 上,它PhotoViewer.dll包含照片查看器,而不是shimgvw.dll。我不知道 Windows 8 上的情况如何)。

于 2013-09-30T19:54:03.210 回答