很多朋友对于delphi $是什么意思和delphi怎样使程序最小化时变成右下角的一个小图标不太懂,今天就由小编来为大家分享,希望可以帮助到大家,下面一起来看看吧!
本文目录
如何用delphi获得网卡的物理地址
Delphi代码获取网卡物理地址
以下是我从MSDN中翻译过来的三个Delphi单元,调用任意一个单元中声明的API都可以获取网卡的物理地址,但三个单元中的API函数的有效环境和功能各有不同,我把说明附于代码的注释中。
unitLmwksta;
interface
uses
Windows,SysUtils,Dialogs;
type
_WKSTA_TRANSPORT_INFO_0=packedrecord
wkti0_quality_of_service:DWORD;
wkti0_number_of_vcs:DWORD;
wkti0_transport_name:PWideChar;{连接设备名称,这个名称是\DEVICE\NetBT_TcpIp……我也不知道如何理解,不过我们只想获取MAC地址就不必管它了!}
wkti0_transport_address:PWideChar;//MAC地址
wkti0_wan_ish:BOOL;//是否是广域网连接
end;
WKSTA_TRANSPORT_INFO_0=_WKSTA_TRANSPORT_INFO_0;
PWKSTA_TRANSPORT_INFO_0=^WKSTA_TRANSPORT_INFO_0;
const
NERR_Success=0;
MAX_PREFERRED_LENGTH=$FFFFFFFF;
//当本计算机有可用的网卡,且已经连接上网络时,调用本函数才能成功,否则获取不到任何信息
functionNetWkstaTransportEnum(
ServerName:PWideChar;//主机名称,传递nil时表示本机
Level:DWORD;//传递0
BufPtr:PPointer;{接受_WKSTA_TRANSPORT_INFO_0记录数组的缓冲区,有此函数自行分配,但使用完后要用下面定义的NetApiBufferFree函数释放内存}
PrefMaxLen:DWORD;//缓冲区最大长度,传递上面定义的MAX_PREFERRED_LENGTH常量即可
EntriesRead,TotalEntries,ResumeHandle:PDWORD):DWORD;stdcall;
{EntriesRead为返回的_WKSTA_TRANSPORT_INFO_0记录数组的元素个数,至于TotalEntries和ResumeHandle,可以传递nil,需要更深入的了解,请参见MSDN}
functionNetApiBufferFree(Buffer:Pointer):DWORD;stdcall;
implementation
functionNetWkstaTransportEnum;external'netapi32.dll'name'NetWkstaTransportEnum';
functionNetApiBufferFree;external'netapi32.dll'name'NetApiBufferFree';
end.
unitRpcdce;
interface
uses
Windows,SysUtils;
type
TUUID=packedrecord
Data1:ULONG;
Data2:Word;
Data3:Word;
Data4:array[0..7]ofByte;//此数组的后6个元素就是网卡的物理地址信息
end;
TGUID=TUUID;
PUUID=^TUUID;
const
{以下为UuidCreateSequential函数的可能返回值}
RPC_S_UUID_LOCAL_ONLY:LongInt=1824;//函数生成的GUID只能保证在本计算机上是唯一的
RPC_S_UUID_NO_ADDRESS:LongInt=1739;//不能获取以太网或令牌环网网卡设备
RPC_S_OK:LongInt=0;//函数调用成功,生成的GUID中包含了网卡的物理地址信息
functionUuidCreateSequential(varuuid:TUUID):Cardinal;stdcall;//此函数只使用于单网卡的机器
functionGetMACAddress:string;
implementation
functionUuidCreateSequential;external'Rpcrt4.dll'name'UuidCreateSequential';
//引用此单元后,只需要调用GetMACAddress函数即可获得网卡物理地址
functionGetMACAddress:string;
var
uuid:TUUID;
I:Integer;
begin
Result:='';
ifUuidCreateSequential(uuid)=RPC_S_OKthen
forI:=2to7do
begin
ifI>2thenResult:=Result+'-';
Result:=Result+IntToHex(uuid.Data4[I],2);
end;
end;
end.
unitIPHlpAPI;
interface
uses
Windows,SysUtils,Classes;
const
MAX_ADAPTER_DESCRIPTION_LENGTH=128;
MAX_ADAPTER_NAME_LENGTH=256;
MAX_ADAPTER_ADDRESS_LENGTH=8;
DEFAULT_MINIMUM_ENTITIES=32;
MAX_HOSTNAME_LEN=128;
MAX_DOMAIN_NAME_LEN=128;
MAX_SCOPE_ID_LEN=256;
ERROR_NO_DATA:LongInt=232;
ERROR_NOT_SUPPORTED:LongInt=50;
ERROR_INVALID_PARAMETER:LongInt=87;
ERROR_BUFFER_OVERFLOW:LongInt=111;
type
time_t=Integer;
IP_ADDRESS_STRING=packedrecord
Addr:array[0..15]ofChar;
end;
PIP_ADDRESS_STRING=^IP_ADDRESS_STRING;
IP_MASK_STRING=IP_ADDRESS_STRING;
PIP_MASK_STRING=^IP_MASK_STRING;
PIPAdapterInfo=^TIPAdapterInfo;
TIPAdapterInfo=packedrecord
Next:PIPAdapterInfo;//下一个节点的指针
ComboIndex:DWORD;
AdapterName:array[0..MAX_ADAPTER_NAME_LENGTH+3]ofChar;//适配器名称
Description:array[0..MAX_ADAPTER_DESCRIPTION_LENGTH+3]ofChar;//适配器描述信息
AddressLength:UINT;//Address域的最大长度,传递MAX_ADAPTER_ADDRESS_LENGTH常量即可
Address:array[0..MAX_ADAPTER_ADDRESS_LENGTH-1]ofByte;//适配器物理地址
Index:DWORD;
uType:UINT;
DhcpEnabled:UINT;
CurrentIpAddress:PIP_ADDRESS_STRING;
IpAddressList:IP_ADDRESS_STRING;
GatewayList:IP_ADDRESS_STRING;
DhcpServer:IP_ADDRESS_STRING;
HaveWins:BOOL;
PrimaryWinsServer:IP_ADDRESS_STRING;
SecondaryWinsServer:IP_ADDRESS_STRING;
LeaseObtained:time_t;
LeaseExpires:time_t;
end;
//此函数功能最强大,而且只要求网卡在系统中可用,并不要求一定连接上网络
functionGetAdaptersInfo(Buf:PIPAdapterInfo;varBufLen:ULONG):DWORD;stdcall;
implementation
functionGetAdaptersInfo;external'iphlpapi.dll'name'GetAdaptersInfo';
end.
对于GetAdaptersInfo函数,Buf参数要求函数的调用者自行分配,如果分配的空间不足,函数返回ERROR_BUFFER_OVERFLOW,BufLen变参的值被设置为实际需要的缓冲区大小,因此可以再行分配,以满足需
求,采用链表遍历操作可以获取所有已安装网卡的物理地址。
Delphi中提取系统时间的函数
1、函数描述:在Delphi中提取系统时间的函数为Time()函数。
2、函数定义:time()函数返回当前系统时间的Unix时间戳。
3、函数语法:time(void)。
4、函数举例:输入代码:<?php$nextWeek=time()+(7*24*60*60);//7days;24hours;60mins;60secsecho'Now:'.date('Y-m-d')."\n";echo'NextWeek:'.date('Y-m-d',$nextWeek)."\n";?>输出结果:Now:2005-03-30NextWeek:2005-04-07
delphi怎样使程序最小化时变成右下角的一个小图标
Shell_NotifyIcon这个API可以实现系统托盘图标功能,然后你在自定义一下最小化的消息就可以了,图标功能有个例子
托盘就是在任务栏右下角的小图标。创建、更改、删除只需要一个WindowsAPI就能实现。这个函数叫做Shell_NotifyIcon()。这个函数和其他处理Windows外壳的函数都包含在ShellAPI单元中。本例程在窗口创建时在任务栏的右下角创建一个托盘图标。图标由两个ICON交替出现。当窗口最小化时任务栏中只有托盘图标,当左键单击托盘图标窗口恢复。图标停止交替。
unitUnit1;
interface
uses
Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,SHELLAPI,
Menus,Dialogs,
ExtCtrls,ImgList;
const
MI_ICONEVENT=WM_USER+1;
ICON_ID=10;
type
TForm1=class(TForm)
Timer1:TTimer;
PopupMenu2:TPopupMenu;
N1:TMenuItem;
ImageList1:TImageList;
procedureN1Click(Sender:TObject);
procedureFormCreate(Sender:TObject);
procedureFormDestroy(Sender:TObject);
procedureFormClose(Sender:TObject;varAction:TCloseAction);
procedureTimer1Timer(Sender:TObject);
private
proceduremodifyicon;
procedureIconOnClick(varmessage:TMessage);MESSAGEMI_ICONEVENT;
proceduretranmessage(varm:TWMSYSCOMMAND);messageWM_SYSCOMMAND;
public
{Publicdeclarations}
end;
var
Form1:TForm1;
ydic:array[0..1]ofticon;
icint:integer;
xsyc:BOOLEAN;
implementation
{$R*.DFM}
procedureTForm1.N1Click(Sender:TObject);
begin
APPLICATION.Terminate;
end;
procedureTForm1.FormCreate(Sender:TObject);
var
IconData:TNotifyIconData;
begin
xsyc:=true;
ydic[0]:=ticon.Create;
ydic[1]:=ticon.Create;
ydic[0].Handle:=loadicon(hinstance,'icon0');//资源文件(ICONS.RES)
ydic[1].Handle:=loadicon(hinstance,'icon1');
IconData.cbSize:=SizeOf(IconData);
IconData.Wnd:=form1.Handle;
IconData.uID:=ICON_ID;
IconData.uFlags:=NIF_ICONorNIF_MESSAGEorNIF_TIP;
IconData.uCallBackMessage:=MI_ICONEVENT;
IconData.hIcon:=ydic[0].Handle;
IconData.szTip:='我笑、我笑、笑笑笑';
icint:=0;
Shell_NotifyIcon(NIM_ADD,@IconData);
ShowWindow(Application.Handle,SW_HIDE);
end;
procedureTForm1.FormDestroy(Sender:TObject);
var
IconData:TNotifyIconData;
begin//卸载图标
IconData.cbSize:=SizeOf(IconData);
IconData.Wnd:=form1.Handle;
IconData.uID:=ICON_ID;
Shell_NotifyIcon(NIM_DELETE,@IconData);
end;
procedureTForm1.FormClose(Sender:TObject;varAction:TCloseAction);
var
IconData:TNotifyIconData;
begin//卸载图标
IconData.cbSize:=SizeOf(IconData);
IconData.Wnd:=form1.Handle;
IconData.uID:=ICON_ID;
Shell_NotifyIcon(NIM_DELETE,@IconData);
end;
procedureTForm1.Timer1Timer(Sender:TObject);
begin
modifyicon
end;
procedureTForm1.modifyicon;
var
IconData:TNotifyIconData;
begin
IconData.cbSize:=SizeOf(IconData);
IconData.Wnd:=form1.Handle;
IconData.uID:=ICON_ID;
icint:=(icint+1)mod2;
IconData.uFlags:=NIF_ICONorNIF_MESSAGEorNIF_TIP;
IconData.uCallBackMessage:=MI_ICONEVENT;
icondata.hIcon:=ydic[icint].Handle;
IconData.szTip:='我笑、我笑、笑笑笑';
shell_notifyicon(nim_modify,@icondata);
end;
procedureTForm1.IconOnClick(varmessage:TMessage);
var
a:tpoint;
begin//单击事件
if(message.lParam=WM_RBUTTONDOWN)then
begin
getcursorpos(a);
PopupMenu2.Popup(a.x,a.y);
end
elseif(message.lParam=WM_LBUTTONDOWN)then
begin
timer1.Enabled:=FALSE;
ifxsycthen
sendmessage(form1.Handle,wm_syscommand,sc_minimize,0)
else
begin
ShowWindow(Application.Handle,SW_RESTORE);//SW_maximize
setforegroundwindow(form1.handle);
xsyc:=true;
end;
end;
end;
procedureTForm1.tranmessage(varm:TWMSYSCOMMAND);
begin
ifm.CmdType=SC_MINIMIZEthen
begin
timer1.Enabled:=true;
sendmessage(Application.Handle,WM_SYSCOMMAND,SC_MINimize,0);
ShowWindow(Application.Handle,SW_HIDE);
xsyc:=false;
end
else
inherited;
end;
end.
最小化消息重载可以这样
procedurepgame(varmsg:twmsyscommand);messagewm_syscommand;
procedureTmainfrm.pgame(varmsg:twmsyscommand);//窗口最小化
begin
ifmsg.CmdType=SC_MINIMIZEthen
begin
//处理代码
end;
inherited;
end;
delphi $是什么意思的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于delphi怎样使程序最小化时变成右下角的一个小图标、delphi $是什么意思的信息别忘了在本站进行查找哦。