最近在做一个往系统光标处设置文本的需求,在网上搜寻了很多资料也没有找到,最后硬啃Windows API文档实现了,关键代码放在这里,以供参考.
在光标处设置文本
首先,先把这些头文件包进去
#include<Textstor.h>
#include<string>
#include<locale>
#include<codecvt>
#include<tchar.h>
#include<iostream>
#include<cstring>
using namespace std;
然后使用下面的代码,就可以在系统任意窗口中的光标闪烁处设置文本了
//在系统光标处设置文本
HWND hwnd = ::GetForegroundWindow();
string text="中文测试代码";
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
wstring tst=converter.from_bytes(text);
const wchar_t *final_text=tst.data();
for(int i=0;final_text[i]!='\0';i++