2

J'ai développé un clavier personnalisé pour WinCE, en utilisant SendInput et un panneau avec des boutons. Le clavier personnalisé fonctionne très bien et la zone de texte dans mon WinForm est capable d'afficher les caractères.Clavier personnalisé avec IME coréen dans WinCE

Actuellement, je suis en train de mettre en œuvre IME coréen dans le clavier personnalisé à l'aide de la méthode suivante:

// Subclass to capture Windows messages, passing the handle of the TextBox 
_newproc = new WndProcDelegate(MyWndProc); 
_oldproc = GetWindowLong(textBox1.Handle, -4); 
result = SetWindowLong(textBox1.Handle, -4, Marshal.GetFunctionPointerForDelegate(_newproc)); 

// Capture the WM_IME_COMPOSITION message to get the composite character 
public IntPtr MyWndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) 
{ 
     switch (msg) 
     { 
      case WM_IME_COMPOSITION: 
      { 
       int comp = lParam.ToInt32(); 
       int intdwSize = 0; 

       if ((comp & GCS_RESULTSTR) > 0) 
        { 
         IntPtr intICHwnd = IntPtr.Zero; 
         intICHwnd = ImmGetContext(hWnd); 

         intdwSize = ImmGetCompositionString(intICHwnd, GCS_RESULTSTR, 0, 0); 
         if (intdwSize != 0) 
         { 
          StringBuilder s = new StringBuilder(intdwSize + 1); 
          intdwSize = ImmGetCompositionString(intICHwnd, GCS_RESULTSTR, s, intdwSize); 
          textBox1.Text = s.ToString(); 
         } 
         ImmReleaseContext(hWnd 
          , intICHwnd); 
        } 
        else if ((comp & GCS_COMPSTR) > 0) 
        { 
         IntPtr intICHwnd = IntPtr.Zero; 

         intICHwnd = ImmGetContext(hWnd); 

         intdwSize = ImmGetCompositionString(intICHwnd, GCS_COMPSTR, 0, 0); 
         if (intdwSize != 0) 
         { 
          StringBuilder s = new StringBuilder(intdwSize); 
          intdwSize = ImmGetCompositionString(intICHwnd, GCS_COMPSTR, s, intdwSize); 
          // Trying to display the composite character in the textbox 
          textBox1.Text = s.ToString(); 
         } 
         ImmReleaseContext(hWnd, intICHwnd); 

        } 
       } 
       break; 


      default: 
       break; 
     } 

    return CallWindowProc(_oldproc, hWnd, msg, wParam, lParam); 
} 

J'ai réussi à capturer le message particulier Windows (WM_IME_COMPOSITION), mais apparemment, le processus de composition ne fonctionne pas à tous, j'essaie toujours de comprendre quelle partie a mal tourné, cependant, j'espère que quelqu'un pourrait me diriger vers la bonne direction, toute aide est appréciée. Merci.

Répondre

1

J'ai trouvé une solution au problème auquel je suis confronté. Le problème ne provient pas du code ci-dessus, mais plutôt les contrôles que j'ai utilisés. Initialement, j'ai testé mon clavier personnalisé avec un textBox et des boutons. Cependant, chaque clic sur le bouton provoque le déplacement du focus de la zone de texte vers le bouton, mettant ainsi fin à la composition. En remplaçant les contrôles Button par PictureBox, la composition est réussie. J'espère que cela t'aides.