vs2010 + richedit20a 获得成功
程序代码:
#include <windows.h> #include <stdio.h> #include <richedit.h> int main() { CHARRANGE stcf; //定义结构,EM_EXSETSEL消息需要此消息, memset(&stcf,0,sizeof(stcf)); //并且将成员变量设置为 -1 是将光标置文本尾部 stcf.cpMax = -1; stcf.cpMin = -1; wchar_t s[]=L"我是第一行数据\r\n我是第二行数据"; int length1=wcslen(s); //printf("字符串长度为%d\n",length1); if (WinExec("c:\\windows\\wordpad.exe",SW_NORMAL)>31) { //printf("成功打开记事本进程\n"); HWND notepadhandle= FindWindow(L"wordpad",NULL); if (notepadhandle!=0) { //printf("能够找到记事本主进程主窗体\n"); HWND childhandle=FindWindowEx(notepadhandle,0,L"RichEdit20A",NULL); if (childhandle!=0) { //AppendTextToRich(s,length1,childhandle); SendMessage(childhandle,EM_EXSETSEL,0,(LPARAM)&stcf); //向RICHEDIT控件发送EM_EXSETSEL消息,选中控件中所有字符 SendMessage(childhandle,EM_REPLACESEL,0,(LPARAM)s); //显示s字符 } } } return 0; }
DO IT YOURSELF !