HWND hwnd = FindWindowA("Notepad",NULL);
HWND childWindow = FindWindowEx(hwnd, 0, NULL, NULL);
// 处理自定义消息的函数
if (childWindow != NULL) {
//方法1
wchar_t s1[] = L"char是C语言标准数据类型 ";
for (size_t i = 0; i < sizeof(s1)/2; i++) //s的长度是wchar_t类型,所以除以2
{
PostMessage(childWindow, WM_CHAR, (WPARAM)(wchar_t)s1[i], 0);
};
//方法2
WPARAM s2[] = { L'语',L'言',L'标',L'准',L' '};
for (size_t i = 0; i < sizeof(s1) / 2; i++) //s的长度是wchar_t类型,所以除以2
{
PostMessage(childWindow, WM_CHAR, (WPARAM)(wchar_t)s1[i], 0);
};
//方法3
PostMessage(childWindow, WM_CHAR, L'字', 1); //单个字输出
PostMessage(childWindow, WM_KEYDOWN, VK_RETURN, NULL);//在记事本中输出回车
cin.get();