找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 5505|回复: 0

分别用c++,c#,vb script 来打开www.baidu.com

[复制链接]
发表于 2011-12-17 20:44:21 | 显示全部楼层 |阅读模式
使用c++:

(下面是传递参数的结构) typedef struct _SHELLEXECUTEINFO {
DWORD cbSize;
ULONG fMask;
HWND hwnd;
LPCTSTR lpVerb;
LPCTSTR lpFile;
LPCTSTR lpParameters;
LPCTSTR lpDirectory;
int nShow;
HINSTANCE hInstApp;
LPVOID lpIDList;
LPCTSTR lpClass;
HKEY hkeyClass;
DWORD dwHotKey;
union {
HANDLE hIcon;
HANDLE hMonitor;
} DUMMYUNIONNAME;
HANDLE hProcess;
} SHELLEXECUTEINFO,
* LPSHELLEXECUTEINFO;


(打开实例) #include < windows.h >
#include
< shellapi.h >
#include
< stdio.h >

int main( int argc, char * argv[])
{

SHELLEXECUTEINFO shell
= { sizeof(shell) };
shell.fMask
= SEE_MASK_FLAG_DDEWAIT;
shell.lpVerb
=
" open " ;
shell.lpFile
=
" IEXPLORE.EXE " ;
shell.lpParameters
=
" http://www.baidu.com " ;
shell.nShow
= SW_SHOWNORMAL;
BOOL ret
= ShellExecuteEx( & shell);

return
0 ;
}


使用c#:
(参数ProcessStartInfo ,参看msdn)
(使用实例 :只有在STA线程上ShellExecute 才能确保工作无误。在Process的实现中,并没有考虑到这个问题,所以使用Process类运行ShellExecute可能会出错。如果你不能保证调用Process.Start的线程的ApartmentState,可以使用如下的代码来避免这个问题:

using System;

using System.Threading;

public class Foo
{

public static void OpenUrl()
{

System.Diagnostics.Process.Start(@
"http://www.baidu.com");

}

public static void Main()
{

ThreadStart openUrlDelegate
=
new ThreadStart(Foo.OpenUrl);

Thread myThread
=
new Thread(openUrlDelegate);

myThread.SetApartmentState(ApartmentState.STA);

myThread.Start();

myThread.Join();

}

}




使用windows脚本:
javascript:

// Create Internet Explorer Object
//
InternetExplorer.Application 运行IE浏览器
ie =
new ActiveXObject("InternetExplorer.Application");

//var ie=wscript.createobject("internetexplorer.application","event_");
//
Define how the window should look

ie.left
=-5;
ie.top
=-25;
ie.height
=860;//高度
ie.width=1035;//宽度
ie.menubar=0;//取消菜单栏
ie.addressbar=0;//取消地址栏
ie.toolbar=0;//取消工具栏
ie.statusbar=0;//取消状态栏
ie.resizable=0;//不允许用户改变窗口大小
ie.visible=1;//窗口可见
ie.navigate("http://www.baidu.com")
//打开窗口





VBScript:

Dim objIE
Set objIE = WScript.CreateObject ("InternetExplorer.Application")
objIE.AddressBar
=
true
objIE.Visible
=
true
objIE.Navigate(
"www.baidu.com")




参考:
http://blogs.msdn.com/oldnewthing/archive/2004/11/26/270710.aspx

http://blog.joycode.com/gangp/archive/2004/08/14/30668.aspx


附录:(来自msdn)
c#:
using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
/**////
<summary>
/// Shell for the sample.
///
</summary>


class MyProcess
{

/**////
<summary>
/// Opens the Internet Explorer application.
///
</summary>


void OpenApplication(string myFavoritesPath)
{
// Start Internet Explorer. Defaults to the home page.
Process.Start("IExplore.exe");

// Display the contents of the favorites folder in the browser.
Process.Start(myFavoritesPath);

}


/**////
<summary>
/// Opens urls and .html documents using Internet Explorer.
///
</summary>


void OpenWithArguments()
{
// url's are not considered documents. They can only be opened
// by passing them as arguments.
Process.Start("IExplore.exe", "www.northwindtraders.com");

// Start a Web page using a browser associated with .html and .asp files.
Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm");
Process.Start(
"IExplore.exe", "C:\\myPath\\myFile.asp");
}


/**////
<summary>
/// Uses the ProcessStartInfo class to start new processes, both in a minimized
/// mode.
///
</summary>


void OpenWithStartInfo()
{

ProcessStartInfo startInfo
=
new ProcessStartInfo("IExplore.exe");
startInfo.WindowStyle
= ProcessWindowStyle.Minimized;

Process.Start(startInfo);

startInfo.Arguments
=
"www.northwindtraders.com";

Process.Start(startInfo);

}


static
void Main()
{
// Get the path that stores favorite links.

string myFavoritesPath =
Environment.GetFolderPath(Environment.SpecialFolder.Favorites);

MyProcess myProcess
=
new MyProcess();

myProcess.OpenApplication(myFavoritesPath);
myProcess.OpenWithArguments();
myProcess.OpenWithStartInfo();

}

}

}



CLI/C++:
#using
<System.dll>

using
namespace System;
using
namespace System::Diagnostics;
using
namespace System::ComponentModel;

/**////
<summary>
/// Opens the Internet Explorer application.
///
</summary>

void OpenApplication( String^ myFavoritesPath )
{

// Start Internet Explorer. Defaults to the home page.
Process::Start( "IExplore.exe" );

// Display the contents of the favorites folder in the browser.
Process::Start( myFavoritesPath );
}



/**////
<summary>
/// Opens urls and .html documents using Internet Explorer.
///
</summary>

void OpenWithArguments()
{

// url's are not considered documents. They can only be opened
// by passing them as arguments.
Process::Start( "IExplore.exe", "www.northwindtraders.com" );

// Start a Web page using a browser associated with .html and .asp files.
Process::Start( "IExplore.exe", "C:\\myPath\\myFile.htm" );
Process::Start(
"IExplore.exe", "C:\\myPath\\myFile.asp" );
}



/**////
<summary>
/// Uses the ProcessStartInfo class to start new processes, both in a minimized
/// mode.
///
</summary>

void OpenWithStartInfo()
{
ProcessStartInfo
^ startInfo = gcnew ProcessStartInfo( "IExplore.exe" );
startInfo
->WindowStyle = ProcessWindowStyle::Minimized;
Process::Start( startInfo );
startInfo
->Arguments =
"www.northwindtraders.com";
Process::Start( startInfo );
}


int main()
{

// Get the path that stores favorite links.
String^ myFavoritesPath = Environment::GetFolderPath( Environment::SpecialFolder::Favorites );
OpenApplication( myFavoritesPath );
OpenWithArguments();
OpenWithStartInfo();
}

您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

Archiver|手机版|小黑屋|ACE Developer ( 京ICP备06055248号 )

GMT+8, 2024-5-2 00:05 , Processed in 0.035386 second(s), 6 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表