zoukankan      html  css  js  c++  java
  • Windows,Com,First Example

    #include <windows.h>
    #include <shobjidl.h> 
    
    int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
    {
        HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | 
            COINIT_DISABLE_OLE1DDE);
        if (SUCCEEDED(hr))
        {
            IFileOpenDialog *pFileOpen;
    
            // Create the FileOpenDialog object.
            hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, 
                IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
    
            if (SUCCEEDED(hr))
            {
                // Show the Open dialog box.
                hr = pFileOpen->Show(NULL);
    
                // Get the file name from the dialog box.
                if (SUCCEEDED(hr))
                {
                    IShellItem *pItem;
                    hr = pFileOpen->GetResult(&pItem);
                    if (SUCCEEDED(hr))
                    {
                        PWSTR pszFilePath;
                        hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
    
                        // Display the file name to the user.
                        if (SUCCEEDED(hr))
                        {
                            MessageBox(NULL, pszFilePath, L"File Path", MB_OK);
                            CoTaskMemFree(pszFilePath);
                        }
                        pItem->Release();
                    }
                }
                pFileOpen->Release();
            }
            CoUninitialize();
        }
        return 0;
    }
    #include <windows.h>
    #include <shobjidl.h> 
    #include <atlbase.h> // Contains the declaration of CComPtr.
    
    int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
    {
        HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | 
            COINIT_DISABLE_OLE1DDE);
        if (SUCCEEDED(hr))
        {
            CComPtr<IFileOpenDialog> pFileOpen;
    
            // Create the FileOpenDialog object.
            hr = pFileOpen.CoCreateInstance(__uuidof(FileOpenDialog));
            if (SUCCEEDED(hr))
            {
                // Show the Open dialog box.
                hr = pFileOpen->Show(NULL);
    
                // Get the file name from the dialog box.
                if (SUCCEEDED(hr))
                {
                    CComPtr<IShellItem> pItem;
                    hr = pFileOpen->GetResult(&pItem);
                    if (SUCCEEDED(hr))
                    {
                        PWSTR pszFilePath;
                        hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
    
                        // Display the file name to the user.
                        if (SUCCEEDED(hr))
                        {
                            MessageBox(NULL, pszFilePath, L"File Path", MB_OK);
                            CoTaskMemFree(pszFilePath);
                        }
                    }
    
                    // pItem goes out of scope.
                }
    
                // pFileOpen goes out of scope.
            }
            CoUninitialize();
        }
        return 0;
    }
  • 相关阅读:
    6美元进公园随便挖钻石

    别了,四方
    九种感觉叫爱情,你遭遇过哪一种?(转)
    我提出辞职,老板竟然让我做选择题(转)
    五大绝招让你永远是人才
    人生必读十大启迪(1):生活到底是什么
    创业95%失败不是因项目本身
    穷国和富国差别在哪里
    一个丑女的感情独白
  • 原文地址:https://www.cnblogs.com/threef/p/3146762.html
Copyright © 2011-2022 走看看