
Introduction
After dialing thru modem and connecting to Internet, we check the status of the connection by invoking the connection status window. This article describes how to invoke the connection status window programatically.In Windows 95,98 and NT it's very simple to invoke the same. Whereas in Windows XP and Windows 2000 we have write our own code to do the same.
Implementation
In Windows NT, we can show this window by means of control panel file Rascpl.cpl. The method is as follows :
WinExec("rundll32.exe shell32.dll,Control_RunDLL Rascpl.cpl,,5",1);
In Windows 9x, say for example the profile which we use to connect to Internet thru dial-up networking is 'Netlink '. Then after the connection is established the connection status window's title will be "Connected to Netlink". So make use of the FindWindow function to invoke the status window. The method is as follows :
if(FindWindow(NULL,"Connected to Netlink"))
{
FindWindow(NULL,"Connected to Netlink")->ShowWindow(1);
}
In Windows XP and Windows 2000, this is not the case, so we have to write our own code get the connection status. For this we need to use the API RasGetConnectionStatistics
and RAS_STATS
structure. But the problem with this API and structure are, though they are present in the rasapi32.lib they are not declared in the ras.h header file. So, we must use the LoadLibray
method and GetProcAddress
function to use the library and the function. And the RAS_STATS
structure must be defined as follows :
typedef struct _RAS_STATS
{
DWORD dwSize;
DWORD dwBytesXmited;
DWORD dwBytesRcved;
DWORD dwFramesXmited;
DWORD dwFramesRcved;
DWORD dwCrcErr;
DWORD dwTimeoutErr;
DWORD dwAlignmentErr;
DWORD dwHardwareOverrunErr;
DWORD dwFramingErr;
DWORD dwBufferOverrunErr;
DWORD dwCompressionRatioIn;
DWORD dwCompressionRatioOut;
DWORD dwBps;
DWORD dwConnectDuration;
} RAS_STATS, *PRAS_STATS;
Conclusion
The Source file and the demo file include here to show the connection status are strictly for Windows XP and Windows 2000. So the Pseudocode for showing the connection status window for the appropriate OS is as follows :
If (OS == IsWin9x())
{
if(FindWindow(NULL,"Connected to Netlink"))
{
FindWindow(NULL,"Connected to Netlink")->ShowWindow(1);
}
}
else If (OS == IsWinNT())
{
WinExec("rundll32.exe shell32.dll,Control_RunDLL Rascpl.cpl,,5",1);
}
if(OS == IsWinXP() || OS == IsWin2k())
{
WinExec("Connectionstatus.exe",1);
}