function TFrmDlg.DMessageDlg(msgstr: string; DlgButtons: TMsgDlgButtons; deftext: string; nt: byte; len: Integer): TModalResult;
const
  XBase = 330;
var
  i: Integer;
  lx, ly: Integer;
  d: TDirectDrawSurface;

  procedure ShowDice();
  var
    i: Integer;
    bo05: Boolean;
  begin
    if m_nDiceCount = 1 then begin
      if m_Dice[0].n67C < 20 then begin
        if GetTickCount - m_Dice[0].dwPlayTick > 100 then begin
          if m_Dice[0].n67C div 5 = 4 then begin
            m_Dice[0].nPlayPoint := Random(6) + 1;
          end else begin
            m_Dice[0].nPlayPoint := m_Dice[0].n67C div 5 + 8;
          end;
          m_Dice[0].dwPlayTick := GetTickCount();
          Inc(m_Dice[0].n67C);
        end;
        Exit;
      end;
      m_Dice[0].nPlayPoint := m_Dice[0].nDicePoint;
      if GetTickCount - m_Dice[0].dwPlayTick > 1500 then begin
        DMsgDlg.Visible := False;
      end;
      Exit;
    end;

    bo05 := True;
    for i := 0 to m_nDiceCount - 1 do begin
      if m_Dice[i].n67C < m_Dice[i].n680 then begin
        if GetTickCount - m_Dice[i].dwPlayTick > 100 then begin
          if m_Dice[i].n67C div 5 = 4 then begin
            m_Dice[i].nPlayPoint := Random(6) + 1;
          end else begin
            m_Dice[i].nPlayPoint := m_Dice[i].n67C div 5 + 8;
          end;
          m_Dice[i].dwPlayTick := GetTickCount();
          Inc(m_Dice[i].n67C);
        end;
        bo05 := False;
      end else begin
        m_Dice[i].nPlayPoint := m_Dice[i].nDicePoint;
        if GetTickCount - m_Dice[i].dwPlayTick < 2000 then begin
          bo05 := False;
        end;
      end;
    end;
    if bo05 then DMsgDlg.Visible := False;
  end;

var
  inputstat, procMsg: Boolean;
  //ln                        : Longint;
  MaxLen: Integer;
begin
  //if DConfigDlg.Visible then //ʾʱرѡ
  //  DOptionClick();
  d := nil;
  DScreen.ClearHint;
  procMsg := False;
  lx := XBase;
  ly := 126;
  case DialogSize of
    0: begin
        d := g_WMainImages.Images[381];
        DMsgDlg.SetImgIndex(g_WMainImages, 381);
        DMsgDlg.Left := (SCREENWIDTH - 188) div 2;
        DMsgDlg.Top := (SCREENHEIGHT - 105) div 2;
        msglx := 39;
        msgly := 38;
        lx := 90;
        ly := 36;
      end;
    1: begin
        d := g_WMainImages.Images[360];
        DMsgDlg.SetImgIndex(g_WMainImages, 360);
        DMsgDlg.Left := (SCREENWIDTH - 452) div 2;
        DMsgDlg.Top := (SCREENHEIGHT - 179) div 2;
        msglx := 39;
        msgly := 38;
        lx := XBase;
        ly := 126;
      end;
    2: begin
        d := g_WMainImages.Images[380];
        DMsgDlg.SetImgIndex(g_WMainImages, 380);
        DMsgDlg.Left := (SCREENWIDTH - 256) div 2;
        DMsgDlg.Top := (SCREENHEIGHT - 359) div 2;
        msglx := 23;
        msgly := 20;
        lx := 90;
        ly := 305;
      end;
  end;
  MsgText := msgstr;
  ViewDlgEdit := False;
  DMsgDlg.Floating := True;
  DxDlgEdit.Visible := False;
  DMsgDlgOk.Visible := False;
  DMsgDlgYes.Visible := False;
  DMsgDlgCancel.Visible := False;
  DMsgDlgNo.Visible := False;
  DMsgDlg.Left := (SCREENWIDTH - DMsgDlg.Width) div 2;
  DMsgDlg.Top := (SCREENHEIGHT - DMsgDlg.Height) div 2;

  for i := 0 to m_nDiceCount - 1 do begin
    m_Dice[i].n67C := 0;
    m_Dice[i].n680 := Random(m_nDiceCount + 2) * 5 + 10;
    m_Dice[i].nPlayPoint := 1;
    m_Dice[i].dwPlayTick := GetTickCount();
  end;

  //EdDlgEdit.Clear;
  DxDlgEdit.Text := '';
  //ln := GetWindowLong(EdDlgEdit.Handle, GWL_STYLE);
  inputstat := DxDlgEdit.NomberOnly;
  if nt = 1 then begin
    //SetWindowLong(EdDlgEdit.Handle, GWL_STYLE, ln or ES_NUMBER);
    DxDlgEdit.NomberOnly := True;
  end;
  MaxLen := DxDlgEdit.MaxLength;
  if len >= 1 then DxDlgEdit.MaxLength := len;
  try
    if mbCancel in DlgButtons then begin
      DMsgDlgCancel.Left := lx;
      DMsgDlgCancel.Top := ly;
      DMsgDlgCancel.Visible := True;
      lx := lx - 92;
    end;
    if mbNo in DlgButtons then begin
      DMsgDlgNo.Left := lx;
      DMsgDlgNo.Top := ly;
      DMsgDlgNo.Visible := True;
      lx := lx - 92;
    end;
    if mbYes in DlgButtons then begin
      DMsgDlgYes.Left := lx;
      DMsgDlgYes.Top := ly;
      DMsgDlgYes.Visible := True;
      lx := lx - 92;
    end;
    if (mbOk in DlgButtons) or (lx = XBase) then begin
      DMsgDlgOk.Left := lx;
      DMsgDlgOk.Top := ly;
      DMsgDlgOk.Visible := True;
      lx := lx - 92;
    end;
    HideAllControls;
    DMsgDlg.ShowModal;

    if mbAbort in DlgButtons then begin
      ViewDlgEdit := True;
      DMsgDlg.Floating := False;
      with DxDlgEdit do begin
        Text := deftext;
        //Width := DMsgDlg.Width - 70;
        //Left := (SCREENWIDTH - DxDlgEdit.Width) div 2;
        //Top := (SCREENHEIGHT - DxDlgEdit.Height) div 2 - 10;
      end;
    end;
    Result := mrOk;

    while True do begin
      if not DMsgDlg.Visible then Break;
      frmMain.AppOnIdle();
      Application.ProcessMessages;
      if m_nDiceCount > 0 then begin
        m_boPlayDice := True;
        for i := 0 to m_nDiceCount - 1 do begin
          m_Dice[i].nX := ((DMsgDlg.Width div 2 + 6) - ((m_nDiceCount * 32 + m_nDiceCount) div 2)) + (i * 32 + i);
          m_Dice[i].nY := DMsgDlg.Height div 2 - 14;
        end;
        ShowDice();
      end;
      Sleep(1); //ڵԻʱCPU 2018-12-23
      if Application.Terminated then Exit;
    end;
  finally
    DxDlgEdit.Visible := False;
    RestoreHideControls;
    DlgEditText := DxDlgEdit.Text;
    if FrmDlg.DEdChat.Visible then FrmDlg.DEdChat.SetFocus;
    ViewDlgEdit := False;
    Result := DMsgDlg.DialogResult;
    DialogSize := 1;
    m_nDiceCount := 0;
    m_boPlayDice := False;

    DxDlgEdit.Text := ''; //Clear;
    DxDlgEdit.MaxLength := MaxLen;
    //SetWindowLong(EdDlgEdit.Handle, GWL_STYLE, ln);
    DxDlgEdit.NomberOnly := inputstat;
  end;
 end;