Q How do I open a file using the application associated with its extension in Windows?
A
If you're writing a .NET application, then life is simple!
Use System.Diagnostics.Process.Start(fileName).
A
If you're writing C or C++, then use the Win32 function ShellExecute(). This calls into the Windows' registry to find the application.
You can specify various parameters that modify how the application starts and how it displays a document.
Visit MSDN and search all topics to find more information.
I've wrapped the function as shown below. It passes MicroStation's native window handle, but that's not essential.
void DisplayFileWithDefaultViewer (const char* path, const char* file)
{
HWND hWnd;
mdlWindow_nativeWindowHandleGet (&hWnd, mdlDialog_overallTitleBarGet (), HANDLETYPE_HWND);
HINSTANCE hInst = ::ShellExecute (hWnd,
NULL, // Verb, e.g. 'open'
file, // Document to open
NULL, // Params if executable
path, // Default directory
SW_SHOWNORMAL); // Window display mode
}
The example above was implemented in a C++ DLL. We haven't tried using it in pure MDL.
Return to MDL articles index.