取屏幕环境相关的多项信息(分辨率、色深、DPI、缩放等),返回逗号分隔的一种字符串,便于一次性掌握当前显示环境。无参数。
本方法无需传入参数。
// 说明:本示例为完整 x64 控制台工程,整段复制覆盖新建控制台工程的 main.cpp 即可编译运行。
// 1. VS2019 新建「控制台应用」,项目属性 -> 平台选 x64,才能加载 64 位 DLL。
// 2. 项目属性 -> C/C++ -> 预编译头 -> 改为「不使用预编译头」,否则默认找 pch.h 会报 C1010。
// 3. 把 x64Game-Plug.dll 放到 exe 同目录(#import 与免注册加载都需要)。
// 4. 源码保存为 UTF-8 带 BOM,避免中文乱码。
#include <iostream>
#include <clocale>
#include <windows.h>
#include <comdef.h>
// 免注册加载:用 IGamePlug 智能指针装载
// rename 是为避开 windows.h 的 FindWindow 宏冲突,接口里的 FindWindow 在 C++ 侧改名为 FindWindowGP
#import "x64Game-Plug.dll" no_namespace rename("FindWindow", "FindWindowGP")
static HMODULE g_hDll = NULL;
static IGamePlugPtr g_plug;
static bool LoadPlug() {
const wchar_t* paths[] = {
L"x64Game-Plug.dll",
L"..\\x64Game-Plug.dll"
};
for (int i = 0; i < (int)(sizeof(paths) / sizeof(paths[0])); ++i) {
g_hDll = ::LoadLibraryW(paths[i]);
if (g_hDll) break;
}
if (!g_hDll) {
std::cout << "LoadLibrary failed: put x64Game-Plug.dll next to the exe" << std::endl;
return false;
}
typedef HRESULT (__stdcall *GamePlugCreateFn)(IGamePlug**);
GamePlugCreateFn fn = (GamePlugCreateFn)::GetProcAddress(g_hDll, "GamePlugCreate");
if (!fn) { std::cout << "GetProcAddress GamePlugCreate failed" << std::endl; return false; }
HRESULT hr = fn(&g_plug);
if (FAILED(hr)) { std::cout << "GamePlugCreate failed: 0x" << std::hex << hr << std::endl; return false; }
return true;
}
int main() {
if (!LoadPlug()) { system("pause"); return 1; }
// ---------- 调用插件本命令方法如下 ----------
try {
_bstr_t info = g_plug->GetScreenInfo();
std::wcout << L"屏幕环境信息: " << (const wchar_t*)info << std::endl;
} catch (_com_error& e) {
std::wcout << L"COM error: " << e.ErrorMessage() << std::endl;
}
g_plug->Release();
system("pause");
return 0;
}
类型 string(BSTR)。返回 7 段逗号分隔:宽,高,色深,系统DPI,缩放%,本进程DPI,DPI一致(1/0)。其中「DPI一致」=1 表示进程已开启 DPI 感知,=0 表示没开启(抓图/坐标可能被系统缩放拉伸)。
1)缩放% 是系统显示缩放(如 125 表示 125%)。2)若「DPI一致」=0,建议调用 SetProcessDpiAware 让进程开启 DPI 感知,否则抓到的画面和坐标会被 Windows 缩放拉伸。3)本功能为免费功能,无需授权码。