我有个问题:在NT系统下,如果网线被拔掉,系统托盘区,会显示一个掉线的提示,请问,能捕获这个消息吗??

解决方案 »

  1.   

    有个API是获得网络连接状况的吧,用返回值来判断。但不记得名字了,可以找一下MSDN
      

  2.   

    //借用别人的把!
    uses WinInet;
    ...procedure TForm1.Button1Click(Sender: TObject);  function GetOnlineStatus : Boolean;
      var ConTypes : Integer;
      begin
        ConTypes := INTERNET_CONNECTION_MODEM + INTERNET_CONNECTION_LAN + INTERNET_CONNECTION_PROXY;
        if (InternetGetConnectedState(@ConTypes, 0) = False)
         then Result := False
         else Result := True;
      end;begin
     if GetOnlineStatus then
       ShowMessage(' Connected')
       else ShowMessage(' not Connected');
    end;
    但注意一个问题:在本地局域网上他也提示connected
      

  3.   

    dickeybird888(于伟刚) :请问你用过NT系统吗??不过,还是要感谢你的回贴!!!
      

  4.   

    對這個問題很有興趣, 我也在網上找過相關資料, 但找不到, 應該是註冊某個對應的消息!!
    關注中, 期待有人給出正确答案!!
    我對要自己用個定時器去檢測或Ping的代碼沒興趣!!!!
      

  5.   

    aiirii(aiirii):我也是啊,但一直找不到答案!!!
      

  6.   

    试试如下:var
      dw: DWORD;
    begin
      hEvent := CreateEvent(nil, TRUE, FALSE, 'RasNotification');
      if hEvent = 0 then
        ShowMessage('Error in CreateEvent')
      else begin
        dw := RasConnectionNotification(INVALID_HANDLE_VALUE,
               hEvent, RASCN_Disconnection+RASCN_Connection);
        if dw <> 0 then
          ShowMessage('Error in RasConnectionNotification')
        else begin
          while true do
          begin
            if WaitForSingleObject(hEvent, INFINITE) = WAIT_OBJECT_0 then
            begin
              ShowMessage('检测到网络连接变化');
              //***********************************************
              //用RasGetConnectStatus得到具体是什么变化
              //***********************************************
              ResetEvent(hEvent);
            end;
          end;
        end;
      end;
      Result := 0
      

  7.   

    function InternetConnected: Boolean;
    const
      // local system uses a modem to connect to the Internet.
      INTERNET_CONNECTION_MODEM      = 1;
      // local system uses a local area network to connect to the Internet.
      INTERNET_CONNECTION_LAN        = 2;
      // local system uses a proxy server to connect to the Internet.
      INTERNET_CONNECTION_PROXY      = 4;
      // local system's modem is busy with a non-Internet connection.
      INTERNET_CONNECTION_MODEM_BUSY = 8;
    var
      dwConnectionTypes : DWORD;
    begin
      dwConnectionTypes := INTERNET_CONNECTION_MODEM+ INTERNET_CONNECTION_LAN
      + INTERNET_CONNECTION_PROXY;
      Result := InternetGetConnectedState(@dwConnectionTypes, 0);
    end;
      

  8.   

    在msdn上有一篇文章說到, 應該是解決方法!我昨晚花了一個小時, 想改成delphi的, 有點問題, 還改不成, 但可先看看, 如果你滿足于VC的解決方法, 那已經有了!ISensNetworkThe ISensNetwork interface handles network events fired by the System Event Notification Service (SENS).
    When To Implement
    Implement this interface on your sink object if you subscribe to any of the SENS network events. Each event corresponds to a method in this interface. This interface is an outgoing interface defined by SENS and implemented by the subscriber application as a dispatch interface.When To Use
    SENS and the COM Event System call the ISensNetwork methods on your sink object to fire the corresponding event.Methods in Vtable Order
    The ISensNetwork interface inherits the methods of the standard COM interface IUnknown.In addition, ISensNetwork defines the following methods. Method Description 
    GetTypeInfoCount Retrieves the number of type descriptions. 
    GetTypeInfo Retrieves a description of the object's programmable interface. 
    GetIDsOfNames Maps name of method or property to DISPID. 
    Invoke Calls one of the object's methods, or gets/sets one of its properties. 
    ConnectionMade Specified connection has been established. 
    ConnectionMadeNoQOCInfo Specified connection has been established with no Quality of Connection information available. 
    ConnectionLost Specified connection has been dropped. 
    DestinationReachable Specified connection can be reached. 
    DestinationReachableNoQOCInfo Specified connection can be reached with no Quality of Connection information. Requirements
    Client: Included in Windows XP, Windows 2000 Professional, and Windows Me.
    Server: Included in Windows Server 2003 and Windows 2000 Server.
    Redistributable: Requires Internet Explorer 5 or later on Windows NT 4.0 and Windows 95/98.
    Header: Declared in Sensevts.h.
    Library: Use Sensevts.tlb.http://msdn.microsoft.com/library/default.asp?url=/library/en-us/syncmgr/syncmgr/isensnetwork.asp