英文:
C send emojis with sendmessage()
问题
我想使用sendmessage()
函数向浏览器(如Chrome或Microsoft Edge)发送表情符号。
当我定义一个带有表情符号的字符串,并使用fputs()
将其写入一个.txt文件时,输出的格式如下所示:❤❤ ++ 😘😘
。
字符串:snprintf(buffer, sizeof(buffer), "\U00002764\U00002764 ++ \U0001F618\U0001F618");
缓冲数组使用char
数据类型。
使用sendmessage()
函数时,我没有得到预期的输出。尝试发送maximizewindow
命令有效。以下是我使用的代码片段:
for (int i = 0; i < strlen(buffer); i++)
{
SendMessage(hwnd, WM_UNICHAR, (WPARAM)0, (LPARAM)buffer[i]);
}
我还尝试过PostMessage()
和PostMessageW()
。
英文:
I want send emojis to a browser like chrome or Microsoft edge with the sendmessage()
function.
When i defined a string with the emojis and write it with fputs()
to a .txt file the output is the expected in format of ❤❤ ++ 😘😘
.
The string: snprintf(buffer, sizeof(buffer), "\U00002764\U00002764 ++ \U0001F618\U0001F618");
The buffer array use the char
datatype.
With the sendmessage()
function i do not get the expected output. Trying to send a maximizewindow command works. Following is my codesnipped i use:
for (int i = 0; i < strlen(buffer); i++)
{
SendMessage(hwnd, WM_UNICHAR, (WPARAM)0, (LPARAM)buffer[i]);
}
I also tryed PostMessage()
and PostMessageW()
.
答案1
得分: 0
我找不到任何方法在几个小时后使用SendMessage()
与WM_UNICHAR
。但是对我来说,我找到了一个很好的替代方案,可以使用SendInput()
。这些函数支持UTF32字符,并在我测试的每个窗口中都能正常工作。接下来,我将发布我的代码以帮助其他人。
short si_ret;
INPUT pInputs;
pInputs.type = INPUT_KEYBOARD;
pInputs.ki.wVk = 0; // 在dwFlags为零时使用普通字符,否则在Unicode上将wVk设置为零
pInputs.ki.wScan = (WORD)0; // 使用L'❤'来发送UTF-32字符,或匹配的值(参见WEB或wprintf)
pInputs.ki.dwFlags = KEYEVENTF_UNICODE;
wchar_t text[] = L"❤❤😘😘";
for (unsigned int x = 0; x < wcslen(text); x++)
{
pInputs.ki.wScan = (WORD)text[x];
if (!(si_ret = SendInput(1, &pInputs, sizeof(pInputs)))) { printf("SendInput do not work [%i]\r\n", GetLastError()); return 0; }
else { printf("SendInput ok [%i]\r\n", si_ret); }
}
希望这有助于您。
英文:
I cant find any way to use SendMessage()
with WM_UNICHAR
after hours. But for me i found a good alternative solution with SendInput()
. These function supports UTF32 characters and works in every window i tested. Following i will post my code to help others.
short si_ret;
INPUT pInputs;
pInputs.type = INPUT_KEYBOARD;
pInputs.ki.wVk = 0; //Use here normal characters when dwFlags zero, otherwise on unicode set wVk to zero
pInputs.ki.wScan = (WORD)0; //Use L'❤' to send UTF-32 characters or the matching value (see WEB or wprintf)
pInputs.ki.dwFlags = KEYEVENTF_UNICODE;
wchar_t text[] = L"❤❤😘😘";
for(unsigned int x = 0; x < wcslen(text); x++)
{
pInputs.ki.wScan = (WORD)text[x];
if(!(si_ret = SendInput(1, &pInputs, sizeof(pInputs)))) { printf("SendInput do not work [%i]\r\n", GetLastError()); return 0; }
else { printf("SendInput ok [%i]\r\n", si_ret); }
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论