C# 程序调用默认浏览器打开网址

发布时间:2010年06月29日      浏览次数:515 次
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace XYAutoSale.Class
{
class OpenIE
{
public static void Open(string sUrl)
{
object url = sUrl;
try
{
// 调用默认浏览器打开网址.
ShellExecute(IntPtr.Zero, "open", sUrl, "", "", ShowCommands.SW_SHOWNOACTIVATE);
}
catch (Exception e)
{
Console.WriteLine("Exception when creating Internet Explorer object {0}", e);
return;
}
}
public enum ShowCommands : int
{
SW_HIDE = 0,
SW_SHOWNORMAL = 1,
SW_NORMAL = 1,
SW_SHOWMINIMIZED = 2,
SW_SHOWMAXIMIZED = 3,
SW_MAXIMIZE = 3,
SW_SHOWNOACTIVATE = 4,
SW_SHOW = 5,
SW_MINIMIZE = 6,
SW_SHOWMINNOACTIVE = 7,
SW_SHOWNA = 8,
SW_RESTORE = 9,
SW_SHOWDEFAULT = 10,
SW_FORCEMINIMIZE = 11,
SW_MAX = 11
}
[DllImport("shell32.dll")]
static extern IntPtr ShellExecute(
IntPtr hwnd,
string lpOperation,
string lpFile,
string lpParameters,
string lpDirectory,
ShowCommands nShowCmd);
}
}
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!