unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 =
class(TForm)
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
public
_AddrChangeEventHandle : THandle;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Function NotifyAddrChange(
Out Handle : THANDLE;
Const Overlapped : OVERLAPPED) : DWORD;
StdCall;
External '
Iphlpapi.dll';
procedure TForm1.FormCreate(Sender: TObject);
Var
H : THandle;
O : OVERLAPPED;
R : DWORD;
begin
_AddrChangeEventHandle:=CreateEvent(
Nil,False,False,
Nil);
O.hEvent:=_AddrChangeEventHandle;
R:=NotifyAddrChange(H,O);
If not ((R = NO_ERROR)
or (R = ERROR_IO_PENDING))
Then RaiseLastOSError();
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
CloseHandle(_AddrChangeEventHandle);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
If (WaitForSingleObject(_AddrChangeEventHandle,0) = WAIT_OBJECT_0)
Then Windows.Beep(1000,100);
end;
end.