How can I move the IME window to a specific position?

thebluetropics 50 Reputation points
2023-02-05T18:31:15.4266667+00:00

User's image

I want to move the IME window to specific position on the screen. And if possible, relative to the client area. How can I achieve this with Win32?

Windows development | Windows API - Win32
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 90,681 Reputation points
    2023-02-06T16:35:52.7633333+00:00

    It seems to work with ImmSetCompositionWindow

    But I had to intercept messages like WM_IME_STARTCOMPOSITION, WM_IME_COMPOSITION, ... in the main message loop

    and I called ImmAssociateContextEx at beginning :

    ImmSetCompositionWindow

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Tong Xu - MSFT 2,546 Reputation points Microsoft External Staff
    2023-02-24T08:13:34.6333333+00:00

    Hi, @thebluetropics

    Using ImmSetCompositionWindow is effective.

    
    if (uMsg == WM_IME_COMPOSITION)
    {
    		
    	
    		HIMC hIMC = ImmGetContext(m_hWnd);
    		if (hIMC) 
    		{
    			// Set composition window position near caret position
    			POINT point;
    			GetCaretPos(&point);
     
    			COMPOSITIONFORM Composition;
    			Composition.dwStyle = CFS_POINT;
    			Composition.ptCurrentPos.x = point.x;
    			Composition.ptCurrentPos.y = point.y;
    			ImmSetCompositionWindow(hIMC, &Composition);
     
    			ImmReleaseContext(m_hWnd,hIMC);
    		}
    

    Thank you.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.