nodejs c++ 获取鼠标选中的数据注意不是复制的内容而是选中的内容 一下是官方的描述请根据这个思路用C++实现并包装成一个方法返回值是char注意中文编码This code help you to get focused control text in focused window i hope that helps Gain focus control You could get the
#include <Windows.h>
#include
char* GetFocusedControlText() { HWND focusedWnd = GetForegroundWindow(); DWORD threadId = GetWindowThreadProcessId(focusedWnd, NULL); DWORD currentThreadId = GetCurrentThreadId(); if (threadId != currentThreadId) { AttachThreadInput(threadId, currentThreadId, TRUE); } HWND focusedCtrl = GetFocus(); int textLength = SendMessageW(focusedCtrl, WM_GETTEXTLENGTH, 0, 0); wchar_t* buffer = new wchar_t[textLength + 1]; SendMessageW(focusedCtrl, WM_GETTEXT, textLength + 1, (LPARAM)buffer); std::wstring wstr(buffer); delete[] buffer; int utf8Length = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL); char* utf8Buffer = new char[utf8Length]; WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, utf8Buffer, utf8Length, NULL, NULL); return utf8Buffer;
原文地址: http://www.cveoy.top/t/topic/gfS9 著作权归作者所有。请勿转载和采集!