Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
some asian words have multi-bytes , I'm trying to simulate the wm_char message to send these words , but failed , even using the binary bytes.

Is there any other method to deal with this ?

What I have tried:

like this :

PostMessage(ctrl_info.ctrl_hwnd , WM_CHAR ,0xbac3,0)


this is a frament code of sending wm_char simulation to notepad's Edit control, I saved the notepad ,find out the message 0xbac3 has been seperated as 0xc300 and 0xba00
Posted
Updated 19-Jun-18 21:51pm
v2
Comments
Jochen Arndt 20-Jun-18 3:56am    
WM_CHAR expects a Unicode character in the wParam paremeter.

What is finally written to file by Notepad depends on the encoding of the file which is the code page of the current user by default but can be changed for new files and is left unchanged with existing Unicode files.

If you find the same bytes as passed (0xC3 and 0xBA resp. 0XBAC3) in the file, you have probably saved the file with UTF-16 encoding.
Yount_0701 20-Jun-18 9:19am    
that's true. the saving operation pop out the dialog , I chose the utf-16 encoding.
But I'm not sure what you mean "WM_CHAR expects a Unicode character in the wParam paremeter." I use binary 0xbac3,that should be a unicode WORD,but the view on notepad makes me confused,it's just some random symbols.
Yount_0701 20-Jun-18 9:19am    
That's true. the saving operation pop out the dialog , I chose the utf-16 encoding.
But I'm not sure what you mean "WM_CHAR expects a Unicode character in the wParam paremeter." I use binary 0xbac3,that should be a unicode WORD,but the view on notepad makes me confused,it's just some random symbols.
Richard MacCutchan 20-Jun-18 10:05am    
That is because notepad is using the English character set, so it does not understand the Unicode codes that you send it.
Richard MacCutchan 20-Jun-18 10:03am    
You have not actually explained what problem you are trying to solve. But it occurs to me that there is most likely a much easier solution than sending WM_CHAR messages to Notepad.

 
Share this answer
 
Comments
Yount_0701 20-Jun-18 3:49am    
SendInput is ok, here i submit some code:

#include <afx.h>

void SendAscii(wchar_t data, BOOL shift);
void SendUnicode(wchar_t data);
void SendKeys(CString msg);

void SendAscii(wchar_t data, BOOL shift)
{
INPUT input[2];
memset(input, 0, 2 * sizeof(INPUT));

if (shift) {
input[0].type = INPUT_KEYBOARD;
input[0].ki.wVk = VK_SHIFT;
SendInput(1, input, sizeof(INPUT));
}

input[0].type = INPUT_KEYBOARD;
input[0].ki.wVk = data;

input[1].type = INPUT_KEYBOARD;
input[1].ki.wVk = data;
input[1].ki.dwFlags = KEYEVENTF_KEYUP;

SendInput(2, input, sizeof(INPUT));

if (shift) {
input[0].type = INPUT_KEYBOARD;
input[0].ki.wVk = VK_SHIFT;
input[0].ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, input, sizeof(INPUT));
}
}


void SendUnicode(wchar_t data)
{
INPUT input[2];
memset(input, 0, 2 * sizeof(INPUT));

input[0].type = INPUT_KEYBOARD;
input[0].ki.wVk = 0;
input[0].ki.wScan = data;
input[0].ki.dwFlags = 0x4;//KEYEVENTF_UNICODE;

input[1].type = INPUT_KEYBOARD;
input[1].ki.wVk = 0;
input[1].ki.wScan = data;
input[1].ki.dwFlags = KEYEVENTF_KEYUP | 0x4;//KEYEVENTF_UNICODE;

SendInput(2, input, sizeof(INPUT));
}

void SendString(CString msg)
{
short vk;
BOOL shift;

USES_CONVERSION;
wchar_t* data = T2W(msg.GetBuffer(0));
int len = wcslen(data);

for(int i=0;i<len;i++)
{
if (data[i]>=0 && data[i]<256)
{ //ascii charactor
vk = VkKeyScanW(data[i]);

if (vk == -1) SendUnicode(data[i]);
else
{
if (vk < 0) vk = ~vk + 0x1;

shift = vk >> 8 & 0x1;

if (GetKeyState(VK_CAPITAL) & 0x1) {
if (data[i]>='a' && data[i]<='z' || data[i]>='A' && data[i]<='Z')
{
shift = !shift;
}
}

SendAscii(vk & 0xFF, shift);
Sleep(100);
}
}
else //unicode
{
SendUnicode(data[i]);
Sleep(100);
}
}
}
WM_CHAR should handle Unicode as described at WM_CHAR message (Windows)[^]. However, the receiving application must be designed to expect a Unicode character.
 
Share this answer
 
v3
Comments
Yount_0701 20-Jun-18 9:20am    
you mean to rewrite the notepad wndproc of dealing with WM_CHAR message?
Richard MacCutchan 20-Jun-18 9:37am    
I don't think Microsoft release the source.
Richard MacCutchan 20-Jun-18 9:40am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900