1.要加一个头文件:
         #include <objsafe.h>

2.在控件头文件中加入:

1 DECLARE_INTERFACE_MAP()
2 BEGIN_INTERFACE_PART(ObjectSafety, IObjectSafety)
3 STDMETHOD(GetInterfaceSafetyOptions)(REFIID riid, DWORD __RPC_FAR *pdwSupportedOptions, DWORD __RPC_FAR *pdwEnabledOptions);
4 STDMETHOD(SetInterfaceSafetyOptions)(REFIID riid, DWORD dwOptionSetMask, DWORD dwEnabledOptions);
5 END_INTERFACE_PART(ObjectSafety)

3.在控件的CPP文件中加入:

  1 BEGIN_INTERFACE_MAP(CVP2PCtrl, COleControl)
2 INTERFACE_PART(CVP2PCtrl, IID_IObjectSafety, ObjectSafety)
3 END_INTERFACE_MAP()
4 // Implementation of IObjectSafety
5 STDMETHODIMP CVP2PCtrl::XObjectSafety::GetInterfaceSafetyOptions(
6 REFIID riid,
7 DWORD __RPC_FAR *pdwSupportedOptions,
8 DWORD __RPC_FAR *pdwEnabledOptions)
9 {
10 METHOD_PROLOGUE_EX(CVP2PCtrl, ObjectSafety)
11
12 if (!pdwSupportedOptions || !pdwEnabledOptions)
13 {
14 return E_POINTER;
15 }
16
17 *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA;
18 *pdwEnabledOptions = 0;
19
20 if (NULL == pThis->GetInterface(&riid))
21 {
22 TRACE("Requested interface is not supported.\n");
23 return E_NOINTERFACE;
24 }
25
26 // What interface is being checked out anyhow?
27 OLECHAR szGUID[39];
28 int i = StringFromGUID2(riid, szGUID, 39);
29
30 if (riid == IID_IDispatch)
31 {
32 // Client wants to know if object is safe for scripting
33 *pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER;
34 return S_OK;
35 }
36 else if (riid == IID_IPersistPropertyBag
37 || riid == IID_IPersistStreamInit
38 || riid == IID_IPersistStorage
39 || riid == IID_IPersistMemory)
40 {
41 // Those are the persistence interfaces COleControl derived controls support
42 // as indicated in AFXCTL.H
43 // Client wants to know if object is safe for initializing from persistent data
44 *pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA;
45 return S_OK;
46 }
47 else
48 {
49 // Find out what interface this is, and decide what options to enable
50 TRACE("We didn't account for the safety of this interface, and it's one we support...\n");
51 return E_NOINTERFACE;
52 }
53 }
54
55 STDMETHODIMP CVP2PCtrl::XObjectSafety::SetInterfaceSafetyOptions(
56 REFIID riid,
57 DWORD dwOptionSetMask,
58 DWORD dwEnabledOptions)
59 {
60 METHOD_PROLOGUE_EX(CVP2PCtrl, ObjectSafety)
61
62 OLECHAR szGUID[39];
63 // What is this interface anyway?
64 // We can do a quick lookup in the registry under HKEY_CLASSES_ROOT\Interface
65 int i = StringFromGUID2(riid, szGUID, 39);
66
67 if (0 == dwOptionSetMask && 0 == dwEnabledOptions)
68 {
69 // the control certainly supports NO requests through the specified interface
70 // so it's safe to return S_OK even if the interface isn't supported.
71 return S_OK;
72 }
73
74 // Do we support the specified interface?
75 if (NULL == pThis->GetInterface(&riid))
76 {
77 TRACE1("%s is not support.\n", szGUID);
78 return E_FAIL;
79 }
80
81 if (riid == IID_IDispatch)
82 {
83 TRACE("Client asking if it's safe to call through IDispatch.\n");
84 TRACE("In other words, is the control safe for scripting?\n");
85 if (INTERFACESAFE_FOR_UNTRUSTED_CALLER == dwOptionSetMask && INTERFACESAFE_FOR_UNTRUSTED_CALLER == dwEnabledOptions)
86 {
87 return S_OK;
88 }
89 else
90 {
91 return E_FAIL;
92 }
93 }
94 else if (riid == IID_IPersistPropertyBag
95 || riid == IID_IPersistStreamInit
96 || riid == IID_IPersistStorage
97 || riid == IID_IPersistMemory)
98 {
99 TRACE("Client asking if it's safe to call through IPersist*.\n");
100 TRACE("In other words, is the control safe for initializing from persistent data?\n");
101
102 if (INTERFACESAFE_FOR_UNTRUSTED_DATA == dwOptionSetMask && INTERFACESAFE_FOR_UNTRUSTED_DATA == dwEnabledOptions)
103 {
104 return NOERROR;
105 }
106 else
107 {
108 return E_FAIL;
109 }
110 }
111 else
112 {
113 TRACE1("We didn't account for the safety of %s, and it's one we support...\n", szGUID);
114 return E_FAIL;
115 }
116 }
117
118 STDMETHODIMP_(ULONG) CVP2PCtrl::XObjectSafety::AddRef()
119 {
120 METHOD_PROLOGUE_EX_(CVP2PCtrl, ObjectSafety)
121 return (ULONG)pThis->ExternalAddRef();
122 }
123
124 STDMETHODIMP_(ULONG) CVP2PCtrl::XObjectSafety::Release()
125 {
126 METHOD_PROLOGUE_EX_(CVP2PCtrl, ObjectSafety)
127 return (ULONG)pThis->ExternalRelease();
128 }

//OK!不会再弹出那个“与ActiveX控件交互不安全“的对话框了~~~

//其中CVP2PCtrl全部要换成你的控件的类名

OCX控件避免弹出安全警告的类的更多相关文章

  1. ocx控件避免弹出警告的类--2

    本文与 OCX控件避免弹出安全警告的类 http://www.cnblogs.com/lidabo/archive/2013/03/26/2981852.html 有些类似,只不过增加了几行代码(红色 ...

  2. 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog

    [源码下载] 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog 作者:webabcd 介绍背水一战 Windows 10 之 控 ...

  3. 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu

    [源码下载] 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu 作者:webabcd 介绍背水一战 Windows 10 之 控件(弹 ...

  4. 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout

    [源码下载] 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout 作者:webabcd 介绍背水一战 Windows 10 之 ...

  5. 控件(弹出类): ToolTip, Popup, PopupMenu

    示例1.ToolTip 的示例Controls/FlyoutControl/ToolTipDemo.xaml <Page x:Class="Windows10.Controls.Fly ...

  6. 小程序中点击input控件键盘弹出时placeholder文字上移

    最近做的一个小程序项目中,出现了点击input控件键盘弹出时placeholder文字上移,刚开始以为是软键盘弹出布局上移问题是传说中典型的fixed 软键盘顶起问题,因此采纳了网上搜到的" ...

  7. 控件(弹出类): FlyoutBase, Flyout, MenuFlyout

    1.FlyoutBase(基类) 的示例Controls/FlyoutControl/FlyoutBaseDemo.xaml <Page x:Class="Windows10.Cont ...

  8. 在指定控件位置弹出popup window

    先看效果图 黄色的就是弹出的popup window 首先自定义一个view用来显示,文件名为layout_my_view.xml <?xml version="1.0" e ...

  9. 问题-PopupMenu是哪个控件调用弹出的?

    相关资料: http://bbs.csdn.net/topics/310195683 问题现象:今天有朋友问我个简单的问题,在多个Edit上弹出菜单,怎么判断是哪个Edit调用的.我想了想这个我还真不 ...

随机推荐

  1. 使用cacheBuilder实现函数防抖

    在接口中出现的相同请求重复且连续发送的情况导致一些业务BUG,需要在接口上实现防抖 使用google的cacheBuilder import com.google.common.cache.Cache ...

  2. BZOJ 3727 PA2014 Final Zadanie 树形DP

    题目大意:给定一棵树,令一个点到全部点的距离与点权的乘积之和为b[i].求每一个点的权值a[i] 首先假设给定a[i]我们能够非常轻松的求出b[i] 可是反过来怎么搞?高斯消元?30W? 考虑已知a[ ...

  3. Spring MVC访问静态资源

    http://www.cnblogs.com/yank/p/4477204.html SpringMVC访问静态资源 在SpringMVC中常用的就是Controller与View.但是我们常常会需要 ...

  4. MySQL插入数据性能调优

    插入数据性能调优总结: 1.SQL插入语句调优 2.如果是InnoDB引擎的话,尝试开启事务,批量提交 3.调整MySQl数据库配置     参考: 百度空间 - MySQL插入数据性能调优 CSDN ...

  5. Jenkins Robot framework 持续集成环境搭建

    为什么我们要引入RF?其实最初我们引入RF是为了能够快速的开展自动化验收测试,为敏捷保驾护航.这其中有个重要的工具Jenkins,同时也是应群里朋友们的要求,这次就来介绍一下RF如何快速便捷的结合Je ...

  6. Django中的模板和分页

    模板 在Templates中添加母版: - 母版...html 母版(master.html)中可变化的地方加入: {%block content%}{%endblock%} 在子版 (usermg. ...

  7. js event 的target 和currentTarget

    target  点击的实际tag currentTarget 绑定事件的target

  8. Struts2 原理(转载)

    图来源于Struts2官方站点,是Struts 2 的整体结构. Struts2框架由3个部分组成:核心控制器FilterDispatcher.业务控制器和用户实现的业务逻辑组件.在这3个部分里,St ...

  9. Android活动条(actionbar)使用具体解释(一)

        活动条(ActionBar)是Android3.0的重要更新之中的一个.ActionBar位于传统标题的位置,其主要提供了例如以下功能:     >显示选项菜单的菜单项,即激昂菜单项显示 ...

  10. HDU 6074 Phone Call LCA + 并查集

    Phone Call Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) Pro ...