MCPcopy Create free account
hub / github.com/MaaXYZ/MaaFramework / connect

Method connect

source/MaaWin32ControlUnit/Manager/Win32ControlUnitMgr.cpp:38–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38bool Win32ControlUnitMgr::connect()
39{
40 connected_ = false;
41 screencap_.reset();
42
43#ifndef MAA_WIN32_COMPATIBLE
44 // 设置 Per-Monitor DPI Aware V2,确保 GetClientRect/GetWindowRect 等 API 返回物理像素。
45 // 修复高 DPI 缩放下 PrintWindow/FramePool 等截图方式只能截取部分区域的问题。
46 auto prev_ctx = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
47 if (prev_ctx) {
48 LogInfo << "SetThreadDpiAwarenessContext to PER_MONITOR_AWARE_V2 success" << VAR_VOIDP(prev_ctx);
49 }
50 else {
51 LogWarn << "SetThreadDpiAwarenessContext failed, error:" << GetLastError();
52 }
53#endif
54
55 if (hwnd_) {
56 if (!IsWindow(hwnd_)) {
57 LogError << "hwnd_ is invalid";
58 return false;
59 }
60 }
61 else {
62 LogWarn << "hwnd_ is nullptr";
63 }
64
65 if (!init_screencap()) {
66 return false;
67 }
68
69 if (mouse_method_ == keyboard_method_) {
70 mouse_ = make_input(mouse_method_);
71 keyboard_ = mouse_;
72 }
73 else {
74 mouse_ = make_input(mouse_method_);
75 keyboard_ = make_input(keyboard_method_);
76 }
77
78 connected_ = true;
79 return true;
80}
81
82std::unordered_map<Win32ControlUnitMgr::ScreencapMethod, std::shared_ptr<ScreencapBase>> Win32ControlUnitMgr::build_screencap_units() const
83{

Callers

nothing calls this directly

Calls 1

resetMethod · 0.45

Tested by

no test coverage detected