📄 name.c
字号:
/*============================================================*/
/* Name.C */
/*============================================================*/
#include "netbios.h"
#include "predef.h"
/*------------------------------------------------------------*/
static NCB NameNcb;
/*------------------------------------------------------------*/
/*Expand User Name to Standard 16 Chars (with NULL Terminator)*/
/*------------------------------------------------------------*/
void MakeStandardName(char far *name)
{
char far *p;
int len;
len=_fstrlen(name);
for(p=name+len;p<name+15;*p++=' ');
name[15]='\0';
}
/*------------------------------------------------------------*/
BOOL AddName(char *Name, BYTE *NameNum)
{
BOOL Status;
memset(&NameNcb,0,sizeof(NCB));
NameNcb.NCB_COMMAND=ADD_NAME;
strcpy((char *)NameNcb.NCB_NAME,Name);
MakeStandardName((char far *)&NameNcb.NCB_NAME);
NetBios((NCB far *)&NameNcb);
while(NameNcb.NCB_CMD_CPLT==NB_COMMAND_PENDING)
{
Beep();
delay(1000);
}
if(NameNcb.NCB_CMD_CPLT!=NB_SUCCESSFULLY_EXECUTED)
{
Status=FALSE;
}
else
{
Status=TRUE;
}
*NameNum=NameNcb.NCB_NUM;
return(status);
}
/*------------------------------------------------------------*/
BOOL DelName(char *Name)
{
BOOL Status;
memset(&NameNcb,0,sizeof(NCB));
NameNcb.NCB_COMMAND=DELETE_NAME;
strcpy((char *)NameNcb.NCB_NAME,Name);
MakeStandardName((char far *)&NameNcb.NCB_NAME);
NetBios((NCB far *)&NameNcb);
while(NameNcb.NCB_CMD_CPLT==NB_COMMAND_PENDING)
if(NameNcb.NCB_CMD_CPLT!=NB_SUCCESSFULLY_EXECUTED)
{
Status=FALSE;
}
else
{
Status=TRUE;
}
return(status);
}
/*------------------------------------------------------------*/
BOOL Determine_Name()
{
char Buffer[40];
char StatusStr[80];
char ID[2];
int i;
BYTE NameNum;
BOOL State;
Get_Status_Bar(StatusStr);
Set_Status_Bar("Trying to determine Current User Name...");
State=FALSE;
strcpy(ID,"A");
for(i=0;i<10 && !State;i++)
{
strcpy(Buffer,"PhoneUser_");
strcat(Buffer,ID);
if(AddName(Buffer,&NameNum)==True)
{
strcpy(SelfName,Buffer);
SelfNameNum=NameNum;
State=TRUE;
}
else
{
ID[0]++;
}
}
Set_Status_Bar(StatusStr);
return(State);
}
/*------------------------------------------------------------*/
/* Trying to Change the Machine Name to a new one */
/*------------------------------------------------------------*/
void Change_Name()
{
char Buffer[40];
char StatusStr[80];
int i;
BYTE NameNum;
Get_Status_Bar(StatusStr);
Set_Status_Bar("Please Enter Current New User Name...");
for(i=55;i<=78;i++)
{
Put_Char(i,1,' ',INPUT_FCOLOR,INPUT_BCOLOR);
}
textcolor(INPUT_FCOLOR);
textbackground(INPUT_BCOLOR);
gotoxy(56,2);
Buffer[0]=16;
cgets(Buffer);
memmove(&Buffer[0],&Buffer[2],strlen(&Buffer[2])+1);
Beep();
for(i=55;i<=78;i++)
{
Put_Char(i,1,' ',BLACK,BLACK);
}
gotoxy(1,1);
if(EmptyStr(Buffer))
{
Set_Status_Bar("Empty Name are entered! Invalid! Press Any Key...");
getch();
}
else
{
if(StrEqual(Buffer,SelfName))
{
Set_Status_Bar("New and Old Name are identical! No change! Press Any Key ...");
getch();
}
else
{
Set_Status_Bar("Now we are changing name to the new one...");
if(AddName(Buffer,&NameNum)==True)
{
SelfNameNum=NameNum; //Cancel Receive Datagram Command of OldName,
Receive_All_Message(); //And Hook Up Another Command with the New One.
DelName(SelfName); //Delete the Old Name.
strcpy(SelfName,Buffer);
Set_Status_Bar("Canging Name Successfully! Press Any Key...");
getch();
}
else
{
Set_Status_Bar("Canging Name Failed! Duplicated! Press Any Key...");
getch();
}
}
}
Refresh_Screen(StatusStr);
}
/*------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -