2013-09-30 53 views
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预览图像。在Windows 8中显示Windows 7 Windows图片查看器

我试了两个,但都返回该文件没有关联的程序? 我在搞什么?

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之前,因此对于代码的基础上,从here来了。

+0

你能比“它返回一个错误”更精确吗?如果你想预览图像,你为什么要硬编码将显示图像的应用程序?为什么不将图像传递给shell并要求它预览它? –

+0

当调试器中的消息是69627776后,Windows在ShellExecuteEx(@SEInfo)和ExitCode上显示错误消息。 – Bill

+0

当我将图像名称传递给shell时,它会运行metro应用程序。 – Bill

回答

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来执行此操作,或者使用LoadLibrary()加载DLL,使用GetProcAddress()找到函数导出并自己调用该函数。

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

相关问题