Click here to Skip to main content
15,929,025 members
Home / Discussions / C#
   

C#

 
AnswerRe: What's the weak point of using static function? Pin
Nick Parker10-May-05 11:25
protectorNick Parker10-May-05 11:25 
AnswerRe: What's the weak point of using static function? Pin
Robert Rohde10-May-05 11:29
Robert Rohde10-May-05 11:29 
GeneralRe: What's the weak point of using static function? Pin
Blue_Skye11-May-05 6:25
Blue_Skye11-May-05 6:25 
GeneralC#, Services, and Application Path Pin
Wackatronic110-May-05 8:48
Wackatronic110-May-05 8:48 
GeneralRe: C#, Services, and Application Path Pin
Wackatronic110-May-05 11:20
Wackatronic110-May-05 11:20 
Generaldetecting an internet connection Pin
Mridang Agarwalla10-May-05 6:42
Mridang Agarwalla10-May-05 6:42 
GeneralRe: detecting an internet connection Pin
Judah Gabriel Himango10-May-05 11:43
sponsorJudah Gabriel Himango10-May-05 11:43 
GeneralNot tested yet but currently in development. BTW: Not 100% accurate by design. Pin
Uwe Keim10-May-05 17:50
sitebuilderUwe Keim10-May-05 17:50 
namespace ZetaLib.Windows.Misc
{
#region Using directives.
// ----------------------------------------------------------------------

using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Forms;

// ----------------------------------------------------------------------
#endregion

/////////////////////////////////////////////////////////////////////////

/// <summary>
/// Class that helps in detecting and establishing connections to the
/// Internet.
/// </summary>
public sealed class InternetConnection
{
#region Public types.
// ------------------------------------------------------------------

/// <summary>
/// The type of the Internet connection.
/// </summary>
public enum ConnectionType
{
#region Enum member.

/// <summary>
/// It cannot be determined whether connected or not.
/// </summary>
Unknown,

/// <summary>
/// No connection at all.
/// </summary>
None,

/// <summary>
/// Connected by modem.
/// </summary>
Modem,

/// <summary>
/// Connected through LAN.
/// </summary>
Lan,

/// <summary>
/// Connected through a proxy server.
/// </summary>
Proxy

#endregion
}

/// <summary>
/// Information about an Internet connection state.
/// </summary>
public sealed class ConnectionStateInfo
{
#region Public methods.

/// <summary>
/// Constructor.
/// </summary>
public ConnectionStateInfo(
ConnectionType connectionType,
bool isOnline,
bool isRasInstalled )
{
this.connectionType = connectionType;
this.isOnline = isOnline;
this.isRasInstalled = isRasInstalled;
}

#endregion

#region Public properties.

/// <summary>
/// Get the type of the connection.
/// </summary>
public ConnectionType ConnectionType
{
get
{
return connectionType;
}
}

/// <summary>
/// Check whether currently is online.
/// </summary>
public bool IsOnline
{
get
{
return isOnline;
}
}

/// <summary>
/// Check whether RAS is installed.
/// </summary>
public bool IsRasInstalled
{
get
{
return isRasInstalled;
}
}

#endregion

#region Private helper.

private ConnectionType connectionType;
private bool isOnline;
private bool isRasInstalled;

#endregion
}

// ------------------------------------------------------------------
#endregion

#region Public methods.
// ------------------------------------------------------------------

/// <summary>
/// Query information about the current Internet connection state.
/// </summary>
/// <returns>Returns the information about the current Internet
/// connection state.</returns>
public static ConnectionStateInfo GetConnectionState()
{
InternetConnectionState flags = 0;

bool isConnected = InternetGetConnectedState(
ref flags,
0 );

// --

if ( !isConnected )
{
return new ConnectionStateInfo(
ConnectionType.None,
false,
false );
}
else
{
ConnectionType connectionType = ConnectionType.None;
bool isOnline = false;
bool isRasInstalled = false;

// --

if ( ((int)flags&0xF)==0 )
{
connectionType = ConnectionType.Unknown;
}
else if ( ((int)flags&0xF)==(int)InternetConnectionState.ModemConnection )
{
connectionType = ConnectionType.Modem;
}
else if ( ((int)flags&0xF)==(int)InternetConnectionState.LanConnection )
{
connectionType = ConnectionType.Lan;
}
else if ( ((int)flags&0xF)==(int)InternetConnectionState.ProxyConnection )
{
connectionType = ConnectionType.Proxy;
}

if ( ((int)flags&(int)InternetConnectionState.Offline)==0 )
{
isOnline = false;
}
else
{
isOnline = true;
}

if ( ((int)flags&(int)InternetConnectionState.RasInstalled)==0 )
{
isRasInstalled = false;
}
else
{
isRasInstalled = true;
}

// --

return new ConnectionStateInfo(
connectionType,
isOnline,
isRasInstalled );
}
}

// ------------------------------------------------------------------
#endregion

#region Private helper.
// ------------------------------------------------------------------

[DllImport("wininet.dll", SetLastError=true)]
static extern bool InternetGetConnectedState(
ref InternetConnectionState flags,
int rReserved );

/// <summary>
/// Flags that indicate the different states.
/// </summary>
[Flags]
private enum InternetConnectionState : int
{
ModemConnection = 0x1,
LanConnection = 0x2,
ProxyConnection = 0x4,
RasInstalled = 0x10,
Offline = 0x20,
Configured = 0x40
}

// ------------------------------------------------------------------
#endregion
}

/////////////////////////////////////////////////////////////////////////
}
Generaldrag and drop Pin
Mridang Agarwalla10-May-05 6:39
Mridang Agarwalla10-May-05 6:39 
GeneralRe: drag and drop Pin
Judah Gabriel Himango10-May-05 7:54
sponsorJudah Gabriel Himango10-May-05 7:54 
GeneralFinding out if XP is SP1 or SP2 Pin
easander10-May-05 4:45
easander10-May-05 4:45 
GeneralRe: Finding out if XP is SP1 or SP2 Pin
Dave Kreskowiak10-May-05 4:52
mveDave Kreskowiak10-May-05 4:52 
GeneralRe: Finding out if XP is SP1 or SP2 Pin
Judah Gabriel Himango10-May-05 4:59
sponsorJudah Gabriel Himango10-May-05 4:59 
GeneralRe: Finding out if XP is SP1 or SP2 Pin
easander10-May-05 5:24
easander10-May-05 5:24 
GeneralMix C++ and C# Pin
Drusemark10-May-05 3:02
Drusemark10-May-05 3:02 
GeneralRe: Mix C++ and C# Pin
Colin Angus Mackay10-May-05 4:03
Colin Angus Mackay10-May-05 4:03 
GeneralRe: Mix C++ and C# Pin
Drusemark10-May-05 7:16
Drusemark10-May-05 7:16 
GeneralRe: Mix C++ and C# Pin
mav.northwind10-May-05 19:59
mav.northwind10-May-05 19:59 
GeneralRe: Mix C++ and C# Pin
Drusemark17-May-05 4:25
Drusemark17-May-05 4:25 
GeneralRe: Mix C++ and C# Pin
mav.northwind17-May-05 4:42
mav.northwind17-May-05 4:42 
GeneralRe: Mix C++ and C# Pin
Drusemark17-May-05 5:32
Drusemark17-May-05 5:32 
QuestionHow to modify the ..... Pin
Shankar Balaji10-May-05 3:01
Shankar Balaji10-May-05 3:01 
AnswerRe: How to modify the ..... Pin
MoustafaS10-May-05 5:30
MoustafaS10-May-05 5:30 
QuestionHow to Rotate Controls Pin
RajeshGuptha10-May-05 2:53
RajeshGuptha10-May-05 2:53 
GeneralSearching a particular node in XML Pin
Shankar Balaji10-May-05 1:45
Shankar Balaji10-May-05 1:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.