MFC: How to open the Windows Open With dialog box (select the program you want to use to open this file)?

When I right-click on a file in the windows in the menu that opens, there is a line Open With...by clicking the button. I can select some program that will open the selected file. So now I need to run this dialog for some file (or just run for "tmp.xml"name) with MFC. I need something like CFileDialogthat allows me to view files.

I found SHOpenWithDialog, but for him the minimum supported client is Windows Vista [only for desktop applications], it would be better to also support Windows XP.

+4
source share
1 answer

So, I found such a solution.

void OpenWith(CString strFileNameToOpen)
{
    TCHAR lpPathBuffer[MAX_PATH];
    GetSystemDirectory(lpPathBuffer, MAX_PATH);
    CString strSystemDir = lpPathBuffer;
    STARTUPINFO si = {0};
    PROCESS_INFORMATION pi = {0};
    strSystemDir.Format(_T("rundll32.exe %s\\shell32.dll,OpenAs_RunDLL %s"), lpPathBuffer, strFileNameToOpen);
    CreateProcess(NULL, strSystemDir.GetBuffer(), NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);
}
0
source

Source: https://habr.com/ru/post/1530045/


All Articles