2013-01-22 27 views
0

我在图像文件上使用其路径中的空格运行PhotoViewer时遇到问题。在图像文件上使用路径中的空格运行Windows PhotoViewer

我使用C++函数CreateProcess,提供一个命令行作为它的参数。命令行模板为:

"rundll32 <path to PhotoViewer.dll> ImageView_Fullscreen <path to image> " 
e.g. 
"rundll32 \"C:\\Program Files\\Windows Photo Viewer\\PhotoViewer.dll\" ImageView_Fullscreen Z:\\Documents\\Projects\\ScreenCapture1\\ScreenCapture\\ScreenCapture\\sample.bmp" 

这里的问题是,必须没有双引号且不能包含空格。

我的代码是多还是少这样

_tcscpy_s(str, 200, _T("rundll32 \"C:\\Program Files\\Windows Photo Viewer\\PhotoViewer.dll\" ImageView_Fullscreen Z:\\Documents\\Projects\\ScreenCapture1\\ScreenCapture\\ScreenCapture\\sample.bmp")); 
CreateProcess(NULL,   // No module name (use command line). 
     str,   // Command line. 
     NULL,   // Process handle not inheritable. 
     NULL,   // Thread handle not inheritable. 
     FALSE,   // Set handle inheritance to FALSE. 
     0,    // No creation flags. 
     NULL,   // Use parent's environment block. 
     NULL,   // Use parent's starting directory. 
     &si,   // Pointer to STARTUPINFO structure. 
     &pi);   // Pointer to PROCESS_INFORMATION structure. 

HANDLE hProcess = pi.hProcess; 
CloseHandle(hProcess); 

现在我要与它的路径空间中的图像文件运行PhotoViewer,例如

C:\the folder\has spaces\the image file.bmp 

回答

1

使用旧的Windows风格的路径如果在其中有波浪形的空间。

例如,

c:\thefol~1\hasspa~1\theima~1.bmp 
+0

你如何转换为这种格式的路径? – poolie

+1

@pool:使用GetShortPathName(https://msdn.microsoft.com/en-us/library/windows/desktop/aa364989.aspx)。但是一个简短的样式路径名并不总是可用的,它可以被系统管理员禁用。 – dalle

相关问题