トップ回答者
ShellExecuteExを利用したWindowsフォトビューアーの印刷について

質問
-
ShellExecuteExを利用した、ファイルの印刷処理について教えてください。
印刷対象のファイル拡張子にWindows7のWindowsフォトビューアーを関連付けた場合、ShellExecuteExでWindowsフォトビューアーの印刷ダイアログを表示し、その後、自プロセスの終了と共に、Windowsフォトビューアーの印刷ダイアログが閉じてしまいます。
ShellExecuteEx実行後、hProcessが返却されないため、Windowsフォトビューアーの終了待ちもできない状況です。
Windowsフォトビューアーの印刷ダイアログを表示し、ユーザが印刷を実行した後に、自プロセスを終了する方法か、あるいは、印刷ダイアログを表示したまま、自プロセスを終了する方法をご存じでしたら、教えてください。
サンプルコードは、以下になりますが、よろしくお願いします。
int _tmain(int argc, _TCHAR* argv[])
{
SHELLEXECUTEINFO sei;
ZeroMemory(&sei, sizeof(SHELLEXECUTEINFO));sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.fMask = SEE_MASK_NOCLOSEPROCESS|SEE_MASK_FLAG_DDEWAIT;
sei.nShow = SW_SHOW ;
sei.lpDirectory = NULL;
sei.lpVerb = _T("print");
sei.lpFile = _T("c:\\1.jpg");
sei.lpParameters = NULL;if ( ShellExecuteEx( &sei ) == FALSE ) {
return -1;
}
printf( "hProcess:%d\n", sei.hProcess );Sleep(1000);
return 0;
}
回答
-
レス付きませんね。
原理的に「不可能」と言っておきましょう。根拠は、
SHELLEXECUTEINFOの説明(英文)のhProcessの説明部分を注意深く読むと、
「Even if fMask is set to SEE_MASK_NOCLOSEPROCESS, hProcess will be NULL if no process was launched. For example, if a document to be launched is a URL and an instance of Microsoft Internet Explorer is already running, it will display the document. No new process is launched, and hProcess will be NULL.」
とあり、NULLになるケースが説明されています。IEに限らないようです(直下のNoteも読みましょう)。
従って、
WaitForSingleObject( sei.hProcess, 0);
の様なコードは、期待通りに動作しないと予測できます。rundll32 "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen 「ファイル名」
を
CreatePreocess()してみる
というのは、考えられますが、期待できる動作か保障できません。
すべての返信
-
レス付きませんね。
原理的に「不可能」と言っておきましょう。根拠は、
SHELLEXECUTEINFOの説明(英文)のhProcessの説明部分を注意深く読むと、
「Even if fMask is set to SEE_MASK_NOCLOSEPROCESS, hProcess will be NULL if no process was launched. For example, if a document to be launched is a URL and an instance of Microsoft Internet Explorer is already running, it will display the document. No new process is launched, and hProcess will be NULL.」
とあり、NULLになるケースが説明されています。IEに限らないようです(直下のNoteも読みましょう)。
従って、
WaitForSingleObject( sei.hProcess, 0);
の様なコードは、期待通りに動作しないと予測できます。rundll32 "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen 「ファイル名」
を
CreatePreocess()してみる
というのは、考えられますが、期待できる動作か保障できません。