ShellExecute(handle,nil,'NOTEPAD.EXE',PCharYourStringVar),nil,SW_SHOW);

解决方案 »

  1.   

    还有,你指定的第4个参数,ShellExecute是让你指定文件的路径,如果你指定的是一个字符串变量的话,它会说文件无法找到
      

  2.   

    var
      a:string;
    begin
      a:='c:\windows\desktop\a.txt';
      ShellExecute(handle,nil,'NOTEPAD.EXE',PChar(a),nil,SW_SHOW);
    end;是绝对路径
      

  3.   

    你的意思是执行shellexecute后,string写入文本
    并且与此同时打开文本??
    我觉得这样不太可能实现
    帮你up吧
      

  4.   

    你的意思是执行shellexecute后,string写入文本 可以:
    获取窗口句柄,用SetWindowText设置 String...
      

  5.   

    是你说要用shellexecute的,非要怪我的话,你也有一半责任哪,误导!!!看下面
    procedure TForm1.Button1Click(Sender: TObject);  function geteditHandle(hwnd:integer;lparam:Longint):boolean; stdcall;
      var
        buffer1: array[0..255] of Char;
        buffer2: array[0..255] of Char;
      begin
        result:=true;
        getclassname(hwnd,buffer1,256);
        if strpas(buffer1)='Edit' then
        begin
          getwindowText(hwnd,buffer2,100);
          pinteger(lparam)^ := hwnd;
          result:=False;
        end;
      end;var
      wh,editwh,tmph:thandle;
      s:string;
    begin
      s:='今天你吃了没有?';
      wh:=findwindow(nil,'无标题 - 记事本');
      if wh<>0 then
      begin
        tmph:=wh;
        enumchildwindows(tmph,@getedithandle,integer(@tmph));
        editwh:=tmph;
        if editwh<>0 then showmessage('哇靠,在这里');
        sendmessage(editwh,wm_settext,0,integer(pchar(s)));
      end;
      else
      showmessage('报告,前方没有发现敌人');
    end;以前用过的一小段,稍微改了一下,应该没问题
      

  6.   

    ShellExecute返回的就是“记事本”的PROCESS,楼上那么麻烦的找句柄干嘛!直接通过PROCESS得到句柄,然后模拟一个Ctrl + V键,不过你首先要把要显示的字符放入“剪贴板”。