Specifies the sound type, as identified by an entry in the [sounds] section of the registry. This parameter can be one of the following values:
Value Sound 0xFFFFFFFF Standard beep using the computer speaker MB_ICONASTERISK SystemAsterisk MB_ICONEXCLAMATION SystemExclamation MB_ICONHAND SystemHand MB_ICONQUESTION SystemQuestion MB_OK SystemDefault
----------------------------------------------
你可以试试自己定义数据包的格式,比如第1、2字节定为命令,后面的定为数据。我在《网页制作评分程序》(呵呵,这是我带的课)中用的就是这个方法,用的控件是TNMUDP,数据库是Access2000,部分代码: ==============================客户端=============================== procedure TForm1.NMUDP1DataReceived(Sender: TComponent; NumberBytes: Integer; FromIP: String; Port: Integer); var MyStream: TMemoryStream; MyReceiveTxt: String; aCmd : TpfCommands; TotalMark: integer; begin MsgSended := false; /////////////////////////////////////////////////////////////// MyStream := TMemoryStream.Create; {建立流} try NMUDP1.ReadStream(MyStream); {接收流} MyStream.Read(aCmd, 1); // read the 1st byte which is a cmd if NumberBytes > 1 then begin SetLength(MyReceiveTxt, NumberBytes-1); {NumberBytes为接收到的字节数} MyStream.Read(MyReceiveTxt[1], NumberBytes -1 ); {读数据} end; finally MyStream.Free; {释放流} end; /////////////////////////////////////////////////////////////// case aCmd of pfInvalidInfo : begin GifLogin.Visible := false; BtnLogin.Enabled := true; MessageBox(Handle,'登录信息不正确!', '出错啦...', MB_OK or MB_ICONSTOP); end; //pfNewUser : fNewUser; pfHello : SendMsgToSvr(', pfHello); pfUserOk : ShowPnls(true); pfNeedPass : SendMsgToSvr(edPass.Text, pfUserPass); pfNewPassOK : MessageBox(Handle,'密码已修改!', '操作完成...', MB_OK or MB_ICONEXCLAMATION); pfPageNot : BtnThisPage.Enabled := false; pfPageYes : BtnThisPage.Enabled := true; pfSiteNot : BtnSite.Enabled := false; pfSiteYes : BtnSite.Enabled := true; pfAddNot : BtnAdd.Enabled := true; // the additional marks are a little bit different from others pfAddYes : BtnAdd.Enabled := false; pfHtmURLOK : begin TotalMark := MTAppear.Value + MTTeches.Value; if MTcbNoTitle.Checked then dec(TotalMark,2); if MTcbName.Checked then dec(TotalMark,1); if MTcbPhoto.Checked then dec(TotalMark,1); if MTcbNotOri.Checked then dec(TotalMark,1); if TotalMark <= 0 then TotalMark := 1; SendMsgToSvr(inttostr(TotalMark), pfHtmMarks); end; {else MessageBox(Handle,'服务器出错,请稍后再试!', '出错啦...', MB_OK or MB_ICONSTOP);} end; end;
procedure TForm1.MsgTimerTimer(Sender: TObject); begin MsgTimer.Enabled := MsgSended; if MsgSended and not UserAlreadyLogged then begin MsgSended := false; BtnLogin.Enabled := true; GifLogin.Visible := false; MessageBox(Handle,'服务器没有响应,请稍后再试!', '出错啦...', MB_OK or MB_ICONSTOP); end; end;
procedure TForm1.NMUDP1InvalidHost(var handled: Boolean); begin MessageBox(Handle,'服务器出错,请稍后再试!', '出错啦...', MB_OK or MB_ICONSTOP); end; ===================================服务器端============================ procedure TForm1.NMUDP1DataReceived(Sender: TComponent; NumberBytes: Integer; FromIP: String; Port: Integer); var MyStream: TMemoryStream; MyReceiveTxt: String; aCmd : TpfCommands; tempItem: TListItem; currentt:_SystemTime; tempstr: string; begin //////////////////receive message////////////////////////////// MyStream := TMemoryStream.Create; {建立流} try NMUDP1.ReadStream(MyStream); {接收流} MyStream.Read(aCmd, 1); // read the 1st byte which is a cmd if NumberBytes > 1 then begin SetLength(MyReceiveTxt, NumberBytes-1); {NumberBytes为接收到的字节数} MyStream.Read(MyReceiveTxt[1], NumberBytes -1 ); {读数据} end; finally MyStream.Free; {释放流} end; ///////////////////run the command///////////////////////////// case aCmd of pfUserEmail : begin with ADOTable2 do if Locate('Email', MyReceiveTxt, []) then begin
SendMsgtoC(', pfNeedPass, FromIP); end else SendMsgtoC(', pfInvalidInfo, FromIP);
end; pfUserPass : begin {if MyReceiveTxt='000' then begin SendMsgtoC(', pfNewUser, FromIP); exit; end;} with ADOTable2 do if Locate('Email', GetEmail(FromIP), []) then if MyReceiveTxt = FieldByName('Pass').AsString then SendMsgtoC(', pfUserOk, FromIP) else begin DeleteClient(FromIP); SendMsgtoC(', pfInvalidInfo, FromIP); end; end;
pfBye : DeleteClient(FromIP);
pfNewPass : begin with ADOTable2 do if Locate('Email', GetEmail(FromIP), []) then begin Edit; FieldByName('Pass').AsString := MyReceiveTxt; FieldByName('LastModify').AsString := DateTimeToStr(Now); ADOTable2.Post; SendMsgtoC(', pfNewPassOk, FromIP); exit; end; end; pfIsPageMarked : begin ADOQuery3.Close; ADOQuery3.SQL.Clear; ADOQuery3.SQL.Add(Format(SqlStr1, ['email', 'marks', 'email', GetEmail(FromIP), 'htmurl', MyReceiveTxt])); ADOQuery3.Open; if ADOTable1.FieldByName('htmurl').AsString <> MyReceiveTxt then SendMsgtoC(', pfPageYes, FromIP) else SendMsgtoC(', pfPageNot, FromIP); end; pfIsSiteMarked : begin ADOQuery3.Close; ADOQuery3.SQL.Clear; ADOQuery3.SQL.Add(Format(SqlStr1, ['email', 'marks', 'email', GetEmail(FromIP), 'htmurl', MyReceiveTxt])); ADOQuery3.Open; if ADOTable1.FieldByName('htmurl').AsString <> MyReceiveTxt then SendMsgtoC(', pfSiteYes, FromIP) else SendMsgtoC(', pfSiteNot, FromIP); end; pfIsAddMarked : begin ADOQuery3.Close; ADOQuery3.SQL.Clear; ADOQuery3.SQL.Add(Format(SqlStr1, ['email', 'marks', 'email', GetEmail(FromIP), 'htmurl', MyReceiveTxt])); ADOQuery3.Open; if ADOTable1.FieldByName('AddMarked').AsString <> 'Y' then SendMsgtoC(', pfAddNot, FromIP) else SendMsgtoC(', pfAddYes, FromIP); end; pfHtmURL : begin ADOTable1.InsertRecord([nil, DateTimeToStr(Now), GetEmail(FromIP), '0', MyReceiveTxt, ', FromIP, 'N','N','0',','0']); SendMsgtoC(', pfHtmURLOK, FromIP); end; pfHtmMarks : begin ADOQuery3.Close; ADOQuery3.SQL.Clear; ADOQuery3.SQL.Add(Format(SqlStr2, ['email', 'marks', 'email', GetEmail(FromIP), 'marks', '0'])); ADOQuery3.Open; if ADOTable1.FieldByName('marks').AsString = '0' then begin ADOTable1.Edit; ADOTable1.FieldByName('marks').AsString := MyReceiveTxt; ADOTable1.Post; SendMsgtoC(', pfMarksOK, FromIP); end //else SendMsgtoC(', pfSthWrong, FromIP); end; pfSiteMarks : begin tempStr := MyReceiveTxt; //mark + site name -> (2+n) Delete(tempStr, 3, length(MyReceiveTxt)); //extract the two part Delete(MyReceiveTxt, 1, 2); //site url and htm url can be stored in one field? just have a try... ADOTable1.InsertRecord([nil, DateTimeToStr(Now), GetEmail(FromIP), ', MyReceiveTxt, ', FromIP, 'Y','N',tempStr,','0']); SendMsgtoC(', pfMarksOK, FromIP); end; pfAddMarks : begin tempStr := MyReceiveTxt; Delete(tempStr, 3, length(MyReceiveTxt)); Delete(MyReceiveTxt, 1, 2); ADOTable1.InsertRecord([nil, DateTimeToStr(Now), GetEmail(FromIP), ', MyReceiveTxt,', FromIP, 'N','Y',',',tempStr]); end; pfWantHistory : begin