OK, thanks to all you folks giving me help, I think I have it. I now use FindExecutable() to get the default program, then CreateProcess() to spawn it:
// Get the name of the program that runs on a .pdf file
char *filename = "C:\\src\\IOGuides\\PDF Files\\751018a.pdf";
TCHAR szExe[MAX_PATH];
::FindExecutable(filename, _T(""), szExe);
HANDLE hProcess = NULL; // Use for WaitForInputIdle()
STARTUPINFO startupInfo;
PROCESS_INFORMATION processInfo;
::ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
::ZeroMemory(&processInfo, sizeof(processInfo)); // better safe than sorry
char cmd[MAX_PATH + MAX_PATH + 5];
sprintf(cmd,"\"%s\" \"%s\"", szExe, filename);
BOOL startedOK = CreateProcess(
NULL,
cmd, // "acrord32.exe file.pdf"
NULL, // Process security
NULL, // Thread security
FALSE, // Inheritance
0, // no special startup flags
NULL, // no special environment
NULL, // no default startup directory
&startupInfo,
&processInfo);
if(!startedOK)
{
ShowLastError(filename);
return;
}
hProcess = processInfo.hProcess;
WaitForInputIdle(hProcess,INFINITE);
I then get the process ID from processInfo.dwProcessId and enumerate all the windows, using GetWindowThreadProcessId() to get the associated process ID.
BOOL CIOGuidesView::enumwndfn(CWnd * wnd)
{
WININFO wininfo(wnd);
wnd->GetWindowText(wininfo.title);
DWORD ProcessId;
GetWindowThreadProcessId (wnd->GetSafeHwnd(), &ProcessId );
wininfo.Pid = ProcessId;
m_WinInfoArray.Add(wininfo);
return TRUE;
}
Comparing processInfo.dwProcessId against the value from GetWindowThreadProcessId() gives me the match-up I needed. Unfortunately, AcroRd32.exe is cutesy and allows only one instance to run at a time. If I already have the Reader running, the new process just closes down. Presumably after talking to its counterpart and giving the new filename. Sigh. I guess I can kill the old one first, but that won't alway work if the user manually started up AcroRd32. Thanks for all your help. I'll probably make a "beginner" level article showing all of this in the next few weeks since doing this is not so obvious. I suspect the trick in making the article will be coming up with keywords and phrases to allow people to find it when they are looking to do this kind of thing. All the information I needed was in the articles; I just couldn't find it. Again, many thanks for all of your