我将在 GUI 应用程序中放置一个网络状态图标。为了获取网络状态通知,我尝试使用 Windows API。为此,我正在考虑在我的应用程序中使用 NetworkAvailabilityChangedEventHandler 。我对使用 Windows API 和框架进行编程非常陌生。任何人都可以帮助我解决以下问题:
- API
NetworkAvailabilityChangedEventHandle
只能在 C# 中使用吗?
- 我可以在 C++ (Qt) 中使用它吗?
- 我必须包含哪个头文件? (我为此检查了 MSDN。但他们为此使用命名空间。所有示例都是 C# 语言。我无法理解如何在我的 C++ 代码中实现它。)
如果有人能给我详细的说明,我将不胜感激使用此 Windows 事件处理程序的代码片段,包括要包含的 .h 文件或命名空间。
I am going to put an network status icon in my GUI application. To get the network status notification, I am trying to use the Windows API. For this I am thinking to use NetworkAvailabilityChangedEventHandler
in my application. I am very new to programming with the Windows API and framework. Can anybody help me in the following things:
- Can the API
NetworkAvailabilityChangedEventHandle
only be used in C#?
- Can I use it in C++ (Qt)?
- Which header file must I include? (I checked in MSDN for this. but they are using namespace for this. All the examples are in C#. I am not able to understand how to implement it in my C++ code.)
I will be grateful if somebody can give me a detailed code snippet for using this windows event handler, including the .h file or namespace to be included.
发布评论
评论(1)
您从哪里想到使用 NetworkAvailabilityChangedEventHandler 委托的想法?
这显然不是 Windows API 的一部分,而是 .NET Framework 与
NetworkChange.NetworkAvailabilityChanged
事件。这就解释了为什么 MSDN 上的所有示例都是用 C# 编写的,因为它仅适用于面向 .NET Framework 的应用程序。如果您使用 Qt 编写非托管 C++,那么您就没有使用 .NET Framework,并且无法利用其功能。等效的 Windows API 是
InternetGetConnectedState
函数 ,它返回一个值,指示系统当前是否连接到互联网。您会发现它的 MSDN 文档对于非托管 C++ 开发人员来说更加友好,因为这就是主要目标受众。您要查找的信息在底部给出:
您可以在此处找到所有 WinINet 函数的列表。
Where did you get the idea to use the
NetworkAvailabilityChangedEventHandler
delegate?That is explicitly not part of the Windows API, but rather a delegate function used by the .NET Framework in conjunction with the
NetworkChange.NetworkAvailabilityChanged
event. That explains why all the examples on MSDN are in C#—because this is only intended to be used in applications targeting the .NET Framework. If you're writing unmanaged C++ using Qt, then you're not using the .NET Framework, and you can't take advantage of its functionality.The Windows API equivalent is the
InternetGetConnectedState
function, which returns a value indicating whether or not the system is currently connected to the Internet. You'll find that its MSDN documentation is substantially friendlier towards unmanaged C++ developers, because that's theprimary intended audience. The information that you're seeking is given at the bottom:
You can find a list of all the WinINet functions here.