主题
保护窗口 - ProtectWindow
函数简介
为指定窗口设置 防截屏保护。被系统或第三方截屏工具捕获时,受保护窗口区域可显示为 黑屏 或 透明,从而避免窗口内容泄露。
支持两种实现方式:
- 驱动模式(
flag= 1、2):经内核驱动拦截截屏,可对 任意进程 的目标窗口生效。 - R3 模式(
flag= 3、4):调用 WindowsSetWindowDisplayAffinity,无需驱动,但 仅对本进程创建的窗口 有效。
传入 flag = 0 可 还原 窗口,取消保护。
接口名称
ProtectWindowDLL调用
c
int32_t ProtectWindow(int64_t instance, int64_t hwnd, int32_t flag);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| hwnd | 长整数型 | 目标窗口句柄。窗口须已创建并完成显示;未就绪时返回 -2(见 返回值)。 |
| flag | 整数型 | 保护标志,详见下方说明。 |
flag 保护标志
| 值 | 模式 | 说明 |
|---|---|---|
| 0 | — | 还原,取消窗口保护。 |
| 1 | 驱动 | 黑屏:截屏时该窗口区域显示为黑色。 |
| 2 | 驱动 | 透明:截屏时该窗口区域显示为透明。 |
| 3 | R3 | 黑屏(R3 模式,基于 SetWindowDisplayAffinity)。 |
| 4 | R3 | 透明(R3 模式,基于 SetWindowDisplayAffinity)。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// flag=1 驱动模式黑屏;取消保护传 0
int ret = ola.ProtectWindow(hwnd, 1);
if (ret == 1) {
// 保护已生效
}csharp
using OLAPlug;
var ola = new OLAPlugServer();
int ret = ola.ProtectWindow(hwnd, 0);python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
ret = ola.ProtectWindow(hwnd, 0)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
int ret = ola.ProtectWindow(hwnd, 0);cpp
var ola = com("OlaPlug.OlaSoft")
var ret = ola.ProtectWindow(hwnd, 0)vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ret = ola.ProtectWindow(hwnd, 0)text
.局部变量 ola, OLAPlug
ola.创建 ()
ret = ola.ProtectWindow(hwnd, 0)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var ret = ola.ProtectWindow(hwnd, 0);text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 ret = ola.ProtectWindow(hwnd, 0)cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int32_t ret = ola.ProtectWindow(hwnd, 0);原生 DLL 调用
cpp
ProtectWindow(instance, hwnd, 0);csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int ProtectWindow(long ola, int hwnd, int flag);
ProtectWindow(instance, hwnd, 0);python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
ola.ProtectWindow(instance, hwnd, 0)返回值
| 返回值 | 说明 |
|---|---|
1 | 成功。 |
-2 | 窗口 未创建完成或者不是可见窗口,请等待窗口创建并显示后再调用。 |
| 其他 | 失败(具体原因与驱动状态、权限、窗口句柄有效性等有关)。 |
注意事项
| 项目 | 说明 |
|---|---|
| 驱动模式(flag 1、2) | 须以 管理员权限 运行;内置欧拉驱动会自动加载,无需手动 LoadDriver。可对 其他进程 的窗口设置保护;自签名驱动 需先 ImportDriverFromFile 或 ImportDriver。 |
| R3 模式(flag 3、4) | 使用 Windows SetWindowDisplayAffinity,不需要驱动;只能保护本进程创建的窗口,无法保护或关闭其他进程窗口。 |
| R3 特征 | R3 模式可能在部分系统或检测场景下留下 特殊窗口特征,隐蔽性通常不如驱动模式。 |
| 窗口就绪 | 目标 hwnd 须为有效且已显示的窗口;过早调用会返回 -2。 |
| 取消保护 | 需要恢复窗口正常显示时,对同一 hwnd 传入 flag = 0。 |
| 与截图模块 | 本接口影响 图像处理 中 Capture、GetScreenData 等对受保护区域的捕获效果;驱动模式与 R3 模式在各类截屏后端上的表现可能略有差异。 |
