COM:The Open Dialog Box
如何使用com组件创建打开对话框
#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;}
使用ATL智能指针CComPtr实现
#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;
}
Asking an Object for an Interface: https://msdn.microsoft.com/en-us/library/ff485837(v=vs.85).aspx
COM:The Open Dialog Box相关推荐
- GP学习(五)—ArcGIS Toolbox Reference dialog box
声明:仅做自己学习整理用,内容拷贝自ArcEngine SDK开发文档 ArcGIS Toolbox Reference dialog box Summary The ArcGIS Toolbox R ...
- java modal_Java 源码-模态对话框(Modal Dialog Box)的实现
所谓的模态对话框,即弹出后用户只能与对话框交互,而不能与背景页面交互的对话框. (modal specifies whether dialog blocks user input to other t ...
- matlab 对话框保持,如何在matlab中创建输入对话框?(How to create Input dialog box in matlab?)...
如何在matlab中创建输入对话框?(How to create Input dialog box in matlab?) 我想在matlab中创建输入对话框. 我在MATLAB中执行简单的加法运算. ...
- 资源——对话框(Dialog Box)
一般菜单项的后面加省略号(...)提示该菜单会激活一个对话框. 对话框的坐标X轴以对话框所用字体宽度的1/4为单位,Y轴以字体高度的1/8为单位. 对话框处理过程与窗口处理过程很相似,但也有一些不同, ...
- R语言ggplot2可视化:箱图(box plot)可视化并且在为箱图的异常值(outlier)添加数据标签
R语言ggplot2可视化:箱图(box plot)可视化并且在为箱图的异常值(outlier)添加数据标签 目录
- Android项目实战(三十二):圆角对话框Dialog
原文:Android项目实战(三十二):圆角对话框Dialog 前言: 项目中多处用到对话框,用系统对话框太难看,就自己写一个自定义对话框. 对话框包括:1.圆角 2.app图标 , 提示文本,关闭对 ...
- react antd confirm content list_React造轮系列:对话框组件 - Dialog 思路
React造轮系列:对话框组件 - Dialog 思路 对话框一般是我们点击按钮弹出的这么一个东西,主要类型有 Alter, Confirm 及 Modal, Modal 一般带有半透明的黑色背景.当 ...
- 论文浅尝 | BoxE:一种基于Box的知识图谱表示学习模型
笔记整理 | 耿玉霞,浙江大学直博生.研究方向:知识图谱,零样本学习等. 论文链接: https://arxiv.org/pdf/2007.06267.pdf 本文是发表在NeurIPS 2020上 ...
- Color dialog box
#include <windows.h>LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK Pan ...
最新文章
- Android应用开发—TextView的动态创建
- oracle数据库imp导入失败提示:“不是有效的导出文件, 标头验证失败”解决方法,修改dmp文件里oracle数据库版本号方法
- UVA 10453—— Make Palindrome
- C/C++求一个整数的二进制中1的个数(用三种效率不同的方法实现)
- 负margin在布局中的运用(*****************************************************************)...
- stream 定长循环_Java8之Stream流代替For循环操作
- Kaggle 数据清洗挑战 Day 5 - 处理不一致数据
- php毛玻璃,CSS实现毛玻璃透明效果
- 如何用shell脚本读取配置文件
- Java 测试使用的类 Test
- 多元有序logistic回归分析_多元logistics回归分析
- L. Collecting Diamonds
- itest英语考试bug_ITEST 使用常见问题之教师篇
- 硬盘坏了数据可以恢复吗?可以分两种情况恢复
- python tkinter 关闭窗口_如何关闭Tkinter窗口?
- 【AcWing 学习】图论与搜索
- 在这里,有人用10万块的电脑刷贴吧,有人用200块的电脑打LOL
- OMAP3530-mini调试笔记(2)
- 华为鸿蒙P10plus,华为P10 Plus全面评测 华为P10 Plus值不值得买
- 【Python界面设计】Tkinter的Listbox控件
热门文章
- 架构师的 36 项修炼1 开篇词:7分钟Get技术人进阶技巧
- 论文分为哪几个级别(一)
- jsonPath解析测试
- loh4j整合flume(log4jsource)
- Android--万能自定义弹窗
- 【uni-app】H5的返回拦截经验分享
- 如何复制360图书馆文章
- java多线程:9、synchronized、Lock的底层实现原理以及和volatile、Lock、ReentrantLock的区别?
- RNA-ATTO 390|RNA-ATTO 425|RNA-ATTO 465|RNA-ATTO 488|RNA-ATTO 495|RNA-ATTO 520近红外荧光染料标记核糖核酸RNA
- 《Android 开发入门与实战(第二版)》——6.10节本章小结