Skip to content

保护窗口 - ProtectWindow

函数简介

为指定窗口设置 防截屏保护。被系统或第三方截屏工具捕获时,受保护窗口区域可显示为 黑屏透明,从而避免窗口内容泄露。

支持两种实现方式:

  • 驱动模式flag = 1、2):经内核驱动拦截截屏,可对 任意进程 的目标窗口生效。
  • R3 模式flag = 3、4):调用 Windows SetWindowDisplayAffinity无需驱动,但 仅对本进程创建的窗口 有效。

传入 flag = 0 可 还原 窗口,取消保护。

接口名称

ProtectWindow

DLL调用

c
int32_t ProtectWindow(int64_t instance, int64_t hwnd, int32_t flag);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
hwnd长整数型目标窗口句柄。窗口须已创建并完成显示;未就绪时返回 -2(见 返回值)。
flag整数型保护标志,详见下方说明。

flag 保护标志

模式说明
0还原,取消窗口保护。
1驱动黑屏:截屏时该窗口区域显示为黑色。
2驱动透明:截屏时该窗口区域显示为透明。
3R3黑屏(R3 模式,基于 SetWindowDisplayAffinity)。
4R3透明(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。可对 其他进程 的窗口设置保护;自签名驱动 需先 ImportDriverFromFileImportDriver
R3 模式(flag 3、4)使用 Windows SetWindowDisplayAffinity不需要驱动只能保护本进程创建的窗口,无法保护或关闭其他进程窗口。
R3 特征R3 模式可能在部分系统或检测场景下留下 特殊窗口特征,隐蔽性通常不如驱动模式。
窗口就绪目标 hwnd 须为有效且已显示的窗口;过早调用会返回 -2
取消保护需要恢复窗口正常显示时,对同一 hwnd 传入 flag = 0
与截图模块本接口影响 图像处理CaptureGetScreenData 等对受保护区域的捕获效果;驱动模式与 R3 模式在各类截屏后端上的表现可能略有差异。