Should I display the Shared Item dialog or GetOpenFileName? (Win32 API)

I am wondering if I am reinventing the wheel here.

In fact, the new Common Item Dialog file browser is much better than the old version of GetOpenFileName (). If the user is on Vista + operating system, I want to use the new dialog, but still have a function for the old dialog on XP, etc.

So I'm wondering if I need to create such a function.

BOOL ShowOpenFileDialog(_Out_ LPTSTR szBuffer, _In_ UINT iBufferSize)
{
    static DWORD dwMajorVersion = 0;

    if (!dwMajorVersion)
        dwMajorVersion = (DWORD)(LOBYTE(LOWORD(GetVersion())));

    if (dwMajorVersion >= 6)    // Vista+
        return ShowNewOpenFileDialog(szBuffer, iBufferSize); // show common item

    return ShowOldOpenFileDialog(szBuffer, iBufferSize);  // fall back to old dialog
}

      

Also would a common C ++ element be used?

+3


source to share


1 answer


As Raymond Chen said, you shouldn't rely on version numbers, only rely on functionality, for example:

BOOL ShowOpenFileDialog(_Out_ LPTSTR szBuffer, _In_ UINT iBufferSize)
{
    IFileDialog *pfd = NULL;
    HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_IFileDialog, (void**)&pfd);
    if (SUCCEEDED(hr))
    {
        // use IFileDialog as needed...
        pfd->Release();
    }
    else
    {
        // use GetOpenFileName() as needed...
    }
}

      



And no, it IFileDialog

doesn't only apply to C ++. It can be used by any language that supports COM, including C, C ++, Delphi, VisualBasic, etc.

+5


source







All Articles