Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am facing a problem in Windows 10 Creators update where, when I try to input something to my application using IME, the first character is ignored; i.e., If I use IME to enter the japanese hiragana character 'か' by typing K & A, i end up getting only 'あ' with the K being lost. This happens to the first character only. But the exact same application works properly in Windows 7~8.

The details are as below:

The application is an MFC MDI application of the Container/Server type. Its working is really simple & straightforward. If a document is open, then when a WM_KEYDOWN is fired, dynamically create a CEdit box and enter the pressed key into the edit box. If the edit box already exists, no need to create it again. Just append the input to the contents of the edit box.

I created 2 sample MFC MDI projects (e.g. MDI_sample1 & MDI_Sample2). Keeping the default cpp & h files as is, just added a new class (e.g. CwEdit) that subclasses the CEdit class to both MDI_Sample1 & MDI_Sample2 projects. Now, in MDI_Sample1, I open the *View.cpp, and add a WindowProc override. In this function, I check for the WM_KEYDOWN message, and on WM_KEYDOWN excepting VK_BACK, VK_ENTER, VK_TAB, I dynamically create an edit box using the CwEdit class, and then SendMessage a WM_KEYDOWN with the current wParam and lParam that I got as arguments of the WindowProc function. Running the program, I create a document and then press the key 'k'. An edit box will get created in the document. If IME is not being used, the character 'k' will also get entered into this newly created edit box. Next,I press 'a'and the character 'a' is appended to 'k' in the edit box. So far so good.

Next, I create a new document again. This time, I activate the windows IME to japanese and input 'k'. Again, an edit box will get created and it will display the 'k' with wavy underlines. I input 'a' and it correctly displays the japanese character 'か'. Again, expected and correct.

I copy this exe file to a windows 10 1709 machine and run it. Again, I repeat the same steps above to input the character 'k'. Without IME being active, the box is created and the 'k' is entered into it. Next I press 'a' and the edit box will correctly read 'ka'. Next, I create a new document. This time, I activate the windows IME to japanese and input 'k'. Again, an edit box will get created but it will be empty. I input 'a' and it now displays the japanese character 'あ'. This behaviour happens to all characters. The first keydown which was used to create the edit box will not be shown when IME is active. But once the edit box is created, everything works fine.

I copy the whole code to MDI_Sample2. But there is one little change. This time, in the view, I override the PreTranslateMessage and do the exact same process which was previously being done inside WindowProc. And remove the WindowProc override. This MDI_Sample2 works perfectly well both on Windows 7 as well as Windows 10 1709 even when the Japanese IME is active.

What I have tried:

The code for the *View.cpp for both the projects are as given below:

MDI_Sample1View.cpp
*******************

C++
BOOL MDI_Sample1View::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
    {
	    // TODO: Add your specialized code here and/or call the base class
	    if(message == WM_CHAR)
	    {
		    int wp = static_cast<int>(wParam);
		    // All printable ascii characters
		    if (wp >= 0x32 && wp <= 0x255)
		    {
			    EnableEdit();
			    M_pEdit->SendMessage(message, wParam, lParam);
			    return TRUE;
		    }
	    }
	    else if(message == WM_KEYDOWN)
	    {
		    if (wParam == VK_ESCAPE)
		    {
			    if(M_pEdit &&
				    GetFocus() == M_pEdit)
			    {
				    DisableEdit();
				    return TRUE;
    			}
	    	}
		    EnableEdit();
    	}
	    return CView::WindowProc(message, wParam, lParam);
    }
MDI_Sample2View.cpp
*******************
C++
BOOL MDI_Sample2View::PreTranslateMessage(MSG* pMsg)
    {
	    // TODO: Add your specialized code here and/or call the base class
	    if(pMsg->message == WM_CHAR)
	    {
		    int wp = static_cast<int>(pMsg->wParam);
		    // All printable ascii characters
		    if (wp >= 0x32 && wp <= 0x255)
		    {
			    EnableEdit();
			    M_pEdit->SendMessage(pMsg->message, pMsg->wParam, pMsg->lParam);
			    return TRUE;
		    }
	    }
	    else if(pMsg->message == WM_KEYDOWN)
	    {
		    if (pMsg->wParam == VK_ESCAPE)
		    {
			    if(M_pEdit &&
				    GetFocus() == M_pEdit)
			    {
				    DisableEdit();
				    return TRUE;
    			}
	    	}
		    EnableEdit();
    	}
	    return CView::PreTranslateMessage(pMsg);
    }
All the other files are the same as created by visual studio when I created the new project.
The CwEdit.cpp class has 2 functions namely Create to create the edit box, and an OnKeyDown which is given below:
C++
void CwSpEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
    {
	    if(nChar == VK_ESCAPE)
    	{
	    	SetWindowText(_T(""));
		    return;
    	}
	    CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
    }
Rest of both the projects are identical. So, what is happening here? Why does WindowProc disregard the first character while PreTranslateMessage works fine?

How do I solve this issue? I need to make it work with WindowProc as it used to.
Posted
Updated 4-Jan-18 4:36am
v3

1 solution

Sounds a bit like locale or language settings. This can also happen when compiling with different string flags. Like for multibyte or unicode.

So check the project settings and the IME for this issues and compile both projects in UNICODE. Microsoft has the tradition to change behavoiur in its different versions of Windows, mostly as bugfixes or newer standards.

Be aware that the chars or japanese signs have higher values than 255, so truncating in char or check below 255 are bugs.
 
Share this answer
 
Comments
princektd 4-Jan-18 20:09pm    
@KarstenK The issue seems to be some under the hood update to how IME works... Everything works the way it is supposed to with Windows 7 ~ Windows 10 upto the Creators Update. The issue pops up once you have updated to Windows 10 build 1709...

The project is already set for Unicode and the issue only happens with the first keystroke on IME. after that, it works fine.
That is, if I use IME to type 'sakura', an edit box is created on the 's' KeyDown event. After creating the edit box, the 's' is entered into it, followed by the rest of the characters so that you finally get 'sakura' which IME converts to the japanese input 'さくら' in the IME composition window, and pressing the Enter key will confirm this word into the created edit box. This is the expected behaviour and works correctly prior to Windows 10 Creators Update. But after updating to the Creator's Update, the same input works differently in that, on the 's' KeyDown, the edit box is created, but after that, for some reason, it does not get included into the IME composition. So, typing 'sakura' as before now inputs 'akura'which IME converts to the japanese input 'あくら'.
The conversion to japanese in itself is correct. In the first case the japanese character is 'さ' which corresponds to 'sa', while in the 2nd case, the first japanese character is 'あ' which correctly corresponds to 'a'. As you can see, the first character 's' is missing. This problem can be seen as you are typing, that is, normally, as soon as you type 's', IME composition window will display it as an 's' with wavy underlines. The next keystroke 'a' will be appended to the existing 's' and will get converted to 'さ'. You dont need to type the whole 'sakura' word to see the issue, as in Windows 10 1709, as you type 's', the edit box will be created, but the IME composition window will not be displayed with the 's' character. The next keystroke 'a' will now open the IME composition window and input 'a' into it, which will be converted to 'あ'. Thus, the first 's' keystroke seems to get discarded somewhere, though debugging generates no errors or warnings.
princektd 4-Jan-18 20:21pm    
Also, as given in the code example, this issue happens when I try to handle the edit box creation in the 'WindowProc' override, while, if I do the editbox creation in 'PreTranslateMessage',it works fine in Win 10 1709 also. Thus the question of what changed in the workings of WindowProc in Windows 10 1709, and how to work around it...

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