Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Lec2Pg10
- Lec2Pg10.cpp
- #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;
- // Создание объекта FileOpenDialog.
- hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
- IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
- if (SUCCEEDED(hr))
- {
- // Показать диалог Open.
- hr = pFileOpen->Show(NULL);
- // Получить имя файла от диалога.
- if (SUCCEEDED(hr))
- {
- IShellItem *pItem;
- hr = pFileOpen->GetResult(&pItem);
- if (SUCCEEDED(hr))
- {
- PWSTR pszFilePath;
- hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
- // Показать имя файла пользователю.
- if (SUCCEEDED(hr))
- {
- MessageBox(NULL, pszFilePath, L"File Path", MB_OK);
- CoTaskMemFree(pszFilePath);
- }
- pItem->Release();
- }
- }
- pFileOpen->Release();
- }
- CoUninitialize();
- }
- return 0;
- }
- Lec2Pg20
- Lec2Pg20.cpp
- #include <windows.h>
- #include <shobjidl.h>
- #include <atlbase.h> // Содержит объявление 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;
- // Создать объект FileOpenDialog.
- hr = pFileOpen.CoCreateInstance(__uuidof(FileOpenDialog));
- if (SUCCEEDED(hr))
- {
- // Show the Open dialog box.
- hr = pFileOpen->Show(NULL);
- // Получить имя файла из диалога.
- if (SUCCEEDED(hr))
- {
- CComPtr<IShellItem> pItem;
- hr = pFileOpen->GetResult(&pItem);
- if (SUCCEEDED(hr))
- {
- PWSTR pszFilePath;
- hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
- // Показать имя файла пользователю.
- if (SUCCEEDED(hr))
- {
- MessageBox(NULL, pszFilePath, L"File Path", MB_OK);
- CoTaskMemFree(pszFilePath);
- }
- }
- // pItem выходит из области видимости.
- }
- // pFileOpen выходит из области видимости.
- }
- CoUninitialize();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement