C++ 获取鼠标选中文字 - Node.js 代码示例
#include <Windows.h>
char* GetSelectedText() { HWND hWnd = GetForegroundWindow(); DWORD pid; DWORD tid = GetWindowThreadProcessId(hWnd, &pid); AttachThreadInput(GetCurrentThreadId(), tid, TRUE); HWND hFocused = GetFocus(); AttachThreadInput(GetCurrentThreadId(), tid, FALSE); const int MAX_LENGTH = 1024; wchar_t buffer[MAX_LENGTH]; SendMessageW(hFocused, WM_GETTEXT, (WPARAM)MAX_LENGTH, (LPARAM)buffer); char* result = new char[MAX_LENGTH]; wcstombs(result, buffer, MAX_LENGTH); return result; }
AI 优化版
原文地址:https://www.cveoy.top/t/topic/ouri 著作权归作者所有。请勿转载和采集!