2013-09-30 50 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上的情況)。

相關問題