@Casper-SC
3546 / 1766 / 188
Регистрация: 27.03.2010
Сообщений: 4,973
|
28.10.2012, 13:22
|
|

Сообщение от Avazart
В C# WinApi, не смешите
?
C# | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| using System;
using System.Runtime.InteropServices;
using System.Windows.Input;
namespace Program.Hotkeys
{
internal class HotKeyWinApi
{
public const int WmHotKey = 0x0312;
[DllImport("user32.dll", SetLastError = true)]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, ModifierKeys fsModifiers, Keys vk);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
}
} |
|
C# | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
| using System;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Net.NetworkInformation;
namespace Program.Web
{
public static class Internet
{
[DllImport("wininet.dll")]
static extern bool InternetGetConnectedState(ref InternetConnectionState lpdwFlags, int dwReserved);
static object _syncObj = new object();
[Flags]
enum InternetConnectionState : int
{
INTERNET_CONNECTION_MODEM = 0x1,
INTERNET_CONNECTION_LAN = 0x2,
INTERNET_CONNECTION_PROXY = 0x4,
INTERNET_RAS_INSTALLED = 0x10,
INTERNET_CONNECTION_OFFLINE = 0x20,
INTERNET_CONNECTION_CONFIGURED = 0x40
}
/// <summary>
/// Проверить, есть ли соединение с интернетом
/// </summary>
/// <returns></returns>
public static Boolean CheckConnection()
{
lock (_syncObj)
{
try
{
InternetConnectionState flags = InternetConnectionState.INTERNET_CONNECTION_CONFIGURED | 0;
bool checkStatus = InternetGetConnectedState(ref flags, 0);
if (checkStatus)
return PingServer(new string[]
{
@"google.com",
@"microsoft.com",
@"ibm.com"
});
return checkStatus;
}
catch
{
return false;
}
}
}
public static bool PingServer(string[] serverList)
{
bool haveAnInternetConnection = false;
Ping ping = new Ping();
for (int i = 0; i < serverList.Length; i++)
{
PingReply pingReply = ping.Send(serverList[i]);
haveAnInternetConnection = (pingReply.Status == IPStatus.Success);
if (haveAnInternetConnection)
break;
}
return haveAnInternetConnection;
}
}
} |
|
Не по теме:
Avazart,

Сообщение от Savvy
Croessmah, а если нужен хук на клавиатуру? я должен всё бросить и педалить на плюсах?
0
|