利用以下程序检测计算机有没有连网,如果有,状态栏显示正常,没有刚显示失败提示!
我试过,没问题。
以下为源代码:
unit newdial;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
KsHooks, KsForms, EpIIForms, OleCtrls, SHDocVw, ComCtrls, StdCtrls,
ExtCtrls, KsControls, KsButtons, EpIIButtons, KsItems, EpIIItems,
KsMenus, EpIIMenus,Winsock, SkinEngine, SkinCtrls, SkinButton; //此处要增加引用winsock;
type
TForm1 = class(TForm)
StatusBar1: TStatusBar;
Panel1: TPanel;
WebBrowser1: TWebBrowser;
scSkinStore1: TscSkinStore;
scSkinEngine1: TscSkinEngine;
EpButton1: TEpButton;
EpButton2: TEpButton;
EpButton3: TEpButton;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure StatusBar1DrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
procedure CustomItem5Click(Sender: TObject);
procedure CustomItem6Click(Sender: TObject);
procedure scButton1Click(Sender: TObject);
procedure EpButton1Click(Sender: TObject);
procedure EpButton3Click(Sender: TObject);
procedure EpButton2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
function FindComputer(ComputerName: string):Boolean;//此处要增加这些声明;
implementation
uses Unit2, Unit3;
{$R *.DFM}
function FindComputer(ComputerName: string):Boolean;
var
WSAData: TWSAData;
HostEnt: PHostEnt;
begin
Result :=True;
WSAStartup(2, WSAData);
HostEnt := gethostbyname(PChar(ComputerName));
if HostEnt = nil then Result := False;
WSACleanup;
end; //此处要定义这个动作;
procedure TForm1.FormCreate(Sender: TObject);
begin
if FindComputer('ntserver')=True then
statusbar1.Panels[0].text:=' 计算机ntserver已找到!'
else
statusbar1.Panels[0].text:='计算机ntserver未找到!';
end;
end.