向目标窗口发送字符串消息


::
 SendMessage (  h  , WM_IME_CHAR  ,(  WPARAM )(0xBABA ),0); //发个汉字
::  SendMessage (  h  , WM_CHAR  ,(  WPARAM  )('A' ),0);  // 发送字母.

也可以用剪贴板:


    if (!OpenClipboard (NULL))
    {
        return -1;
    }
    // Remove the current Clipboard contents 
    if(!EmptyClipboard ())
    {
        return -2; 
    }


    // Get the currently selected data, hData handle to
    // global memory of data
    CString str = _T( "teststr");
    size_t cbStr = (str. GetLength() + 1) * sizeof (TCHAR);
    HGLOBAL hData = GlobalAlloc( GMEM_MOVEABLE, cbStr );
    memcpy_s(GlobalLock (hData), cbStr, str .LockBuffer(), cbStr);
    GlobalUnlock(hData );
    str.UnlockBuffer ();


    // For the appropriate data formats...
    UINT uiFormat = (sizeof(TCHAR) == sizeof(WCHAR)) ? CF_UNICODETEXT : CF_TEXT;
    if (::SetClipboardData (uiFormat, hData) == NULL ) 
    {
        CloseClipboard();
        return -3; 
    } 
    CloseClipboard();
    return 0;
发送消息:
SendMessage
PostMessage
PostThreadMessage
EnumThreadWindows  // 枚举线程窗口



你可能感兴趣的:(向目标窗口发送字符串消息)