已经用HOOK取得输入的内容,,现在如何替换为我想要输出的字符串,如何将它发送到目标编辑器。是用SendMessage吗?? 看有人VB是这么写的,VC要怎样写呢,,我没转成.  Const   WM_IME_CHAR   =   &H286   
  Const   WM_IME_COMPOSITION   =   &H10F   
    
  Dim   str   As   String   
  str   =   "你好吗^_^"   
  For   i   =   1   To   Len(str)   
  PostMessage   hwnd,   WM_IME_COMPOSITION,   0,   &H800   
  SendMessage   hwnd,   WM_IME_CHAR,   Asc(Mid(str,   i,   1)),   ByVal   1&   
  Next 不明白VC怎搞,,高手指点一下。截获中文输入的贴子
http://topic.csdn.net/u/20080619/10/26afe8b3-46c8-4dbe-85fa-d42d19f4632f.html?1769754779

解决方案 »

  1.   

    CString str = _T("你好吗^_^");
    PostMessage(hwnd, WM_IME_COMPOSITION, 0, 0x0800);
    SendMessage(hwnd, WM_IME_CHAR, str[i], 1);
      

  2.   

    CString str = _T("你好吗^_^"); 
    for(int i=1;i<=GetLen(str);i++)
    {
    PostMessage(hwnd, WM_IME_COMPOSITION, 0, 0x0800); 
    SendMessage(hwnd, WM_IME_CHAR, str[i], 1);
    }
      

  3.   

    会死循环的重复输入啊char*   str="bbbd";
    int len = _tcslen(str);
    for(int i=1;i<=len;i++) 

       PostMessage(pmsg->hwnd, WM_IME_COMPOSITION, 0, 0x0800); 
       SendMessage(pmsg->hwnd, WM_IME_CHAR, str[i], 1); 
    }
    完整的代码如下case WM_IME_COMPOSITION:
    //MessageBox(NULL, "ImmGetContext3", "ImmGetContext3", MB_OK);
    //m_hEditWnd = pmsg->hwnd;
    //if   (m_hEditWnd   ==   pmsg->hwnd)
    {
                    HIMC hIMC;
                    HWND hWnd=pmsg->hwnd;
                    DWORD dwSize;
                    //char ch;
                    
                    if(pmsg->lParam & GCS_RESULTSTR)
                    {
                        //先获取当前正在输入的窗口的输入法句柄
                        hIMC = ImmGetContext(hWnd);
                        if (!hIMC)
                        {
                            MessageBox(NULL, "ImmGetContext", "ImmGetContext", MB_OK);
                        }                    // 先将ImmGetCompositionString的获取长度设为0来获取字符串大小.
                        dwSize = ImmGetCompositionString(hIMC, GCS_RESULTSTR, NULL, 0);                    // 缓冲区大小要加上字符串的NULL结束符大小,
                        //   考虑到UNICODE
                        dwSize += sizeof(WCHAR);                    memset(lpstr, 0, 20);                    // 再调用一次.ImmGetCompositionString获取字符串
                        ImmGetCompositionString(hIMC, GCS_RESULTSTR, lpstr, dwSize);
    //char*   buf="bbbd";   
    //SendMessage(pmsg->hwnd,WM_SETTEXT,0,(long)buf);
    //ImmGetCompositionString(hIMC, CS_NOMOVECARET, "end", 3);
    //SendMessage(hWnd,WM_SETTEXT,null,(long)buf); char*   str="bbbd";
    int len = _tcslen(str);
    for(int i=1;i<=len;i++) 

    PostMessage(pmsg->hwnd, WM_IME_COMPOSITION, 0, 0x0800); 
    SendMessage(pmsg->hwnd, WM_IME_CHAR, str[i], 1); 
    }                    //现在lpstr里面即是输入的汉字了。你可以处理lpstr,当然也可以保存为文件...
                        //MessageBox(NULL, lpstr, lpstr, MB_OK); 
    //SaveLog(lpstr); 
    FILE* f1;
    f1=fopen("c:\\report_cn.txt","a+");
    //char ch1;
    //ch1=(char)(pmsg->wParam);
    fwrite(lpstr,_tcslen(lpstr),1,f1);
    fclose(f1);
                        ImmReleaseContext(hWnd, hIMC);
                    }
                }
                break;
      

  4.   

    已经可以了,这样就对了
    char*   str="bbbd";
    int len = _tcslen(str);
    for(int i=1;i<=len;i++) 

    //PostMessage(pmsg->hwnd, WM_IME_COMPOSITION, 0, 0x0800); 
    SendMessage(pmsg->hwnd, WM_IME_CHAR, str[i], 1); 
    }