use use InterentGetConnectedState + InternetAutoDial API

解决方案 »

  1.   

    This will be helpful for you.
    http://expert.csdn.net/Expert/topic/948/948369.xml?temp=.285763
      

  2.   

    我的意思是在Form1中点击一个按钮,来调用默认连接,连接成功以后返回一个值给调用程序
      

  3.   

    class abc
    {
    [STAThread]
    static void Main(string[] args)
    {
    try
    {
    int flags=0;
    if (Win32API.InternetGetConnectedState(ref flags,0))
    MessageBox.Show("You are on line");
    else
    {
    Win32API.InternetAutodial(1,IntPtr.Zero);\\如果调用成功返回true,如果需要知道是否连接成功,再次调用InternetGetConnectedState,查询flags参数
    }
    }
    catch (Exception E)
    {
    MessageBox.Show(E.Message);
    }
    }
    }
    public class Win32API
    {
    [DllImport("wininet.dll")]
    public static extern bool InternetGetConnectedState(
    [In, Out, MarshalAs(UnmanagedType.U4)] ref int lpdwFlags, int dwReserved);[DllImport("wininet.dll",EntryPoint="InternetAutodial")]
    public static extern bool InternetAutodial([MarshalAs(UnmanagedType.U4)] int dwFlags,IntPtr hwndParent);
    }
    }
      

  4.   

    谢谢,那么在点击这个按钮时怎样弹出Windows的连接窗口呢
      

  5.   

    我是想做一个计算上网时间的程序,在点击连接按钮后,调用Windows的连接窗口,然后再进行连接,当连接成功以后开始记时