在网上找了以下代码可以向记事本中输入字符:
HWND hWnd=::FindWindow("Notepad",NULL);   
if(hWnd)   
{   
           HWND  hEdit=FindWindowEx(hWnd,NULL,"Edit",NULL);   
    if(hEdit)   
    {
         PostMessage(hEdit,WM_CHAR,XXX,0);           }
}     现在的问题是,我有一个CString str="∑",想要把它输入到记事本,那个PostMessage应该怎么写呢???注:
char str[3] = "∑"; 分别postMessage(str[0]) postMessage(str[1])
这个方法我试过了,结果会输出两个奇怪的字符,而不会输出一个"∑"

解决方案 »

  1.   

    这种像记事本写的操作方法没用过 我用的都是CFile类 的write()方法  很简单  定义一个CFile 类型,完后用成员函数OPen 打开txt,再往里面写write(),完后关闭close().就行了   你上网上或者书上或者CSDN查查CFile怎么用 很多的  
      

  2.   

    #include "stdafx.h"
    #include <iostream.h>
    #include <windows.h>
    #include "stdio.h"int main(int argc, char * argv[])
    {
    HANDLE hFile;
    char wBuffer[1024] = "Σ";
    DWORD writtenNum;
    hFile = CreateFile("Hello.txt",GENERIC_WRITE,
                                FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,0); if(hFile != INVALID_HANDLE_VALUE)
    {
    WriteFile(hFile,wBuffer,1024,&writtenNum,NULL);
    if (writtenNum !=0)
    printf("Write %d bytes success!\n",writtenNum);
    else printf("Write error!\n");
    }
    printf("The data is %s",wBuffer);
    CloseHandle(hFile);
    return 0;
    }
      

  3.   

    HWND hWnd=::FindWindow("Notepad",NULL);    
    CEdit *pwnd;
    if(hWnd)    
    {    
    pwnd = (CEdit*)FindWindowEx(hWnd,NULL,"Edit",NULL);    
    if(pwnd)    

    pwnd->ReplaceSel("∑");
             } 
    }     
      

  4.   

    pwnd->SetSel()可以先设定替换的位置.
      

  5.   


    pwnd = (CEdit*)FindWindowEx(hWnd,NULL,"Edit",NULL); 这句话出错啊
      

  6.   

    我是在一个对话框类里试的,FindWindowEx返回的是指针.
    你的程序里返回的应该是句柄.
    你把句柄转换成指针就行了.
      

  7.   

    HWND hWnd=::FindWindow("Notepad",NULL);    
    CEdit *pwnd;
    HWND hEdit;
    CString s;
    if(hWnd)    
    {    
    hEdit = ::FindWindowEx(hWnd,NULL,"Edit",NULL);    
    pwnd = (CEdit*)CWnd::FromHandle(hEdit);
    if(pwnd)    

    pwnd->ReplaceSel("∑");
            } 
      

  8.   

    发送这两个字符:0xa1和0xc6你用UltraEdit打开包含有∑字符的记事本就知道了
      

  9.   

    在c语言中可以用
    printf("%c%c\n",0xa1, 0xc6);
    输出‘∑’,在任意文本文件中可以按住“Alt”键同时用小键盘区的数字键输入“41414”即可输入‘∑’。