Tester à chaque instant si je suis connecté ou pas sur internet
bonjour;
* j'ai developpé une petite application qui calcul le temps de connextion.
* Cette application execute au demarage de la machine.
voila le code :
Code:
1 2 3 4 5
| TRegistry *Reg = new TRegistry();
Reg->RootKey = HKEY_LOCAL_MACHINE;
Reg->OpenKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", false);
Reg->WriteString("ControlInternet", "C:\\Project1.exe");
delete Reg; |
* Et lancer en mode Tray Icon.
voila le code:
Code:
1 2 3 4
| TrayIcon1->Icons=ImageList1;
TrayIcon1->Visible=true;
TrayIcon1->Minimize();
TrayIcon1->Animate=true; |
* J'ai utilise un compteur à l'aide de Timer:
Code:
1 2 3 4 5 6 7
| void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
int nombre ;
nombre = 0 ;
nombre++ ;
Label1->Caption = Label1->Caption.ToInt() + 1 ;
} |
* Pour test si je suis connecter ou pas , j'ai utilisé le code suivant:
Code:
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
| typedef BOOL (WINAPI *PF_INETGETCONNECTEDSTATE)(LPDWORD, DWORD);
HANDLE hWinInet;
PF_INETGETCONNECTEDSTATE pfInternetGetConnectedState;
//.............
hWinInet = LoadLibrary("WININET.DLL"); //Chargement de la dll
if(hWinInet == NULL)
{
Label1->Caption = "Impossible de charger Wininet.dll";
return;
}
pfInternetGetConnectedState = (PF_INETGETCONNECTEDSTATE) GetProcAddress(
hWinInet, "InternetGetConnectedState");
// affectation du pointeur sur la fonction
if(pfInternetGetConnectedState == NULL)
{
Label1->Caption = "Erreur appel fonction InternetGetConnectedState";
if(hWinInet) FreeLibrary(hWinInet);
return;
}
//.............
DWORD TypeCon ;
if (pfInternetGetConnectedState(&TypeCon, 0)) //appel de la fonction
{
Timer1->Enabled = true ;
Label2->Caption = "Connecté";
}
else
{
Timer1->Enabled = false ;
Label2->Caption = "Déconnecté";
}
//.............
if(hWinInet) FreeLibrary(hWinInet); |
* le probleme est :
ou je mit le teste? (tanque l'application est en execution je teste si je suis
conncté sur interner ou pas).
remarque : l'application est mode Tray Icon