Created
December 15, 2012 12:19
-
-
Save ElemarJR/4294344 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment