var
  Form1: TForm1;
  exeh:hwnd;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
exeh:=ShellExecute (handle,'open','explorer.exe','http://www.5566.org','',SW_SHOW);
end;procedure TForm1.Button2Click(Sender: TObject);
begin
PostMessage(exeh,WM_CLOSE,0,0);
end;end.

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShellExecute(handle,'open','explorer.exe','http://www.5566.org','',SW_SHOW);
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      exeh := FindWindow('ieframe',nil);
      PostMessage(exeh,WM_CLOSE,0,0);
    end;
      

  2.   

    这样不是把IE都给关了吗  我只想关掉我打开的IE
      

  3.   

    其实我是想启动一个外部文件,并得到那个文件的句柄,可怎么不行呢 还有
    ShellExecute(handle,'open','explorer.exe','http://www.5566.org','',SW_SHOW);最后一个参数根本就没有作用 我换成SW_HIDE窗口还是显示的,TMD不能隐藏 只好改用WINEXEC了
    DELPHI要我怎么求救你
      

  4.   

    那可以这样,先用 Finwindow 找到Desktop窗口句柄,所有窗口都是它的子窗口(如你有SPY++会看得很清楚),调用GetWindow()选GW_CHILD 可得其子窗口,选GW_HWNDNEXT或调用GetNextWindow()可得其平级下一窗口,作一递归函数既可得到你所打开的IE窗口句柄了
      

  5.   

    用CreateProcess可以取得启动应用程序的句柄
      

  6.   

    这不是Delphi的问题,楼主你的方法不对,这样你用C,C++,VB,Java,C#等等都是不行的。ShellExecute返回的不是句柄,是 是否成功的标志。
    下面是它返回值的含义:
    0 The operating system is out of memory or resources. 
    ERROR_FILE_NOT_FOUND The specified file was not found. 
    ERROR_PATH_NOT_FOUND The specified path was not found. 
    ERROR_BAD_FORMAT The .exe file is invalid (non-Microsoft Win32 .exe or error in .exe image). 
    SE_ERR_ACCESSDENIED The operating system denied access to the specified file. 
    SE_ERR_ASSOCINCOMPLETE The file name association is incomplete or invalid. 
    SE_ERR_DDEBUSY The Dynamic Data Exchange (DDE) transaction could not be completed because other DDE transactions were being processed. 
    SE_ERR_DDEFAIL The DDE transaction failed. 
    SE_ERR_DDETIMEOUT The DDE transaction could not be completed because the request timed out. 
    SE_ERR_DLLNOTFOUND The specified dynamic-link library (DLL) was not found. 
    SE_ERR_FNF The specified file was not found. 
    SE_ERR_NOASSOC There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable. 
    SE_ERR_OOM There was not enough memory to complete the operation. 
    SE_ERR_PNF The specified path was not found. 
    SE_ERR_SHARE A sharing violation occurred. 
    当你使用一个不是很了解的Windows API的时候,最好上MSDN看看。