ShowMessage是ShowModal一个窗口,接收字符串后输出,具体看看帮助啊

解决方案 »

  1.   

    一步一步来:)
    1:
    procedure ShowMessage(const Msg: string);
    begin
      ShowMessagePos(Msg, -1, -1);
    end;
    2:
    procedure ShowMessagePos(const Msg: string; X, Y: Integer);
    begin
      MessageDlgPos(Msg, mtCustom, [mbOK], 0, X, Y);
    end;
    3:
    function MessageDlgPos(const Msg: string; DlgType: TMsgDlgType;
      Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer): Integer;
    begin
      Result := MessageDlgPosHelp(Msg, DlgType, Buttons, HelpCtx, X, Y, '');
    end;
    4:
    function MessageDlgPosHelp(const Msg: string; DlgType: TMsgDlgType;
      Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer;
      const HelpFileName: string): Integer;
    begin
      with CreateMessageDialog(Msg, DlgType, Buttons) do
        try
          HelpContext := HelpCtx;
          HelpFile := HelpFileName;
          if X >= 0 then Left := X;
          if Y >= 0 then Top := Y;
          if (Y < 0) and (X < 0) then Position := poScreenCenter;
          Result := ShowModal;
        finally
          Free;
        end;
    end;
    5:
    function CreateMessageDialog(const Msg: string; DlgType: TMsgDlgType;
      Buttons: TMsgDlgButtons): TForm;
    const
      mcHorzMargin = 8;
      mcVertMargin = 8;
      mcHorzSpacing = 10;
      mcVertSpacing = 10;
      mcButtonWidth = 50;
      mcButtonHeight = 14;
      mcButtonSpacing = 4;
    var
      DialogUnits: TPoint;
      HorzMargin, VertMargin, HorzSpacing, VertSpacing, ButtonWidth,
      ButtonHeight, ButtonSpacing, ButtonCount, ButtonGroupWidth,
      IconTextWidth, IconTextHeight, X, ALeft: Integer;
      B, DefaultButton, CancelButton: TMsgDlgBtn;
      IconID: PChar;
      TextRect: TRect;
    begin
      Result := TMessageForm.CreateNew(Application);
      with Result do
      begin
        BiDiMode := Application.BiDiMode;
        BorderStyle := bsDialog;
        Canvas.Font := Font;
        DialogUnits := GetAveCharSize(Canvas);
        HorzMargin := MulDiv(mcHorzMargin, DialogUnits.X, 4);
        VertMargin := MulDiv(mcVertMargin, DialogUnits.Y, 8);
        HorzSpacing := MulDiv(mcHorzSpacing, DialogUnits.X, 4);
        VertSpacing := MulDiv(mcVertSpacing, DialogUnits.Y, 8);
        ButtonWidth := MulDiv(mcButtonWidth, DialogUnits.X, 4);
        for B := Low(TMsgDlgBtn) to High(TMsgDlgBtn) do
        begin
          if B in Buttons then
          begin
            if ButtonWidths[B] = 0 then
            begin
              TextRect := Rect(0,0,0,0);
              Windows.DrawText( canvas.handle,
                PChar(LoadResString(ButtonCaptions[B])), -1,
                TextRect, DT_CALCRECT or DT_LEFT or DT_SINGLELINE or
                DrawTextBiDiModeFlagsReadingOnly);
              with TextRect do ButtonWidths[B] := Right - Left + 8;
            end;
            if ButtonWidths[B] > ButtonWidth then
              ButtonWidth := ButtonWidths[B];
          end;
        end;
        ButtonHeight := MulDiv(mcButtonHeight, DialogUnits.Y, 8);
        ButtonSpacing := MulDiv(mcButtonSpacing, DialogUnits.X, 4);
        SetRect(TextRect, 0, 0, Screen.Width div 2, 0);
        DrawText(Canvas.Handle, PChar(Msg), Length(Msg)+1, TextRect,
          DT_EXPANDTABS or DT_CALCRECT or DT_WORDBREAK or
          DrawTextBiDiModeFlagsReadingOnly);
        IconID := IconIDs[DlgType];
        IconTextWidth := TextRect.Right;
        IconTextHeight := TextRect.Bottom;
        if IconID <> nil then
        begin
          Inc(IconTextWidth, 32 + HorzSpacing);
          if IconTextHeight < 32 then IconTextHeight := 32;
        end;
        ButtonCount := 0;
        for B := Low(TMsgDlgBtn) to High(TMsgDlgBtn) do
          if B in Buttons then Inc(ButtonCount);
        ButtonGroupWidth := 0;
        if ButtonCount <> 0 then
          ButtonGroupWidth := ButtonWidth * ButtonCount +
            ButtonSpacing * (ButtonCount - 1);
        ClientWidth := Max(IconTextWidth, ButtonGroupWidth) + HorzMargin * 2;
        ClientHeight := IconTextHeight + ButtonHeight + VertSpacing +
          VertMargin * 2;
        Left := (Screen.Width div 2) - (Width div 2);
        Top := (Screen.Height div 2) - (Height div 2);
        if DlgType <> mtCustom then
          Caption := LoadResString(Captions[DlgType]) else
          Caption := Application.Title;
        if IconID <> nil then
          with TImage.Create(Result) do
          begin
            Name := 'Image';
            Parent := Result;
            Picture.Icon.Handle := LoadIcon(0, IconID);
            SetBounds(HorzMargin, VertMargin, 32, 32);
          end;
        with TLabel.Create(Result) do
        begin
          Name := 'Message';
          Parent := Result;
          WordWrap := True;
          Caption := Msg;
          BoundsRect := TextRect;
          BiDiMode := Result.BiDiMode;
          ALeft := IconTextWidth - TextRect.Right + HorzMargin;
          if UseRightToLeftAlignment then
            ALeft := Result.ClientWidth - ALeft - Width;
          SetBounds(ALeft, VertMargin,
            TextRect.Right, TextRect.Bottom);
        end;
        if mbOk in Buttons then DefaultButton := mbOk else
          if mbYes in Buttons then DefaultButton := mbYes else
            DefaultButton := mbRetry;
        if mbCancel in Buttons then CancelButton := mbCancel else
          if mbNo in Buttons then CancelButton := mbNo else
            CancelButton := mbOk;
        X := (ClientWidth - ButtonGroupWidth) div 2;
        for B := Low(TMsgDlgBtn) to High(TMsgDlgBtn) do
          if B in Buttons then
            with TButton.Create(Result) do
            begin
              Name := ButtonNames[B];
              Parent := Result;
              Caption := LoadResString(ButtonCaptions[B]);
              ModalResult := ModalResults[B];
              if B = DefaultButton then Default := True;
              if B = CancelButton then Cancel := True;
              SetBounds(X, IconTextHeight + VertMargin + VertSpacing,
                ButtonWidth, ButtonHeight);
              Inc(X, ButtonWidth + ButtonSpacing);
              if B = mbHelp then
                OnClick := TMessageForm(Result).HelpButtonClick;
            end;
      end;
    end;
      

  2.   

    一步一步来:)
    1:
    procedure ShowMessage(const Msg: string);
    begin
      ShowMessagePos(Msg, -1, -1);
    end;
    2:
    procedure ShowMessagePos(const Msg: string; X, Y: Integer);
    begin
      MessageDlgPos(Msg, mtCustom, [mbOK], 0, X, Y);
    end;
    3:
    function MessageDlgPos(const Msg: string; DlgType: TMsgDlgType;
      Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer): Integer;
    begin
      Result := MessageDlgPosHelp(Msg, DlgType, Buttons, HelpCtx, X, Y, '');
    end;
    4:
    function MessageDlgPosHelp(const Msg: string; DlgType: TMsgDlgType;
      Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer;
      const HelpFileName: string): Integer;
    begin
      with CreateMessageDialog(Msg, DlgType, Buttons) do
        try
          HelpContext := HelpCtx;
          HelpFile := HelpFileName;
          if X >= 0 then Left := X;
          if Y >= 0 then Top := Y;
          if (Y < 0) and (X < 0) then Position := poScreenCenter;
          Result := ShowModal;
        finally
          Free;
        end;
    end;
    5:
    function CreateMessageDialog(const Msg: string; DlgType: TMsgDlgType;
      Buttons: TMsgDlgButtons): TForm;
    const
      mcHorzMargin = 8;
      mcVertMargin = 8;
      mcHorzSpacing = 10;
      mcVertSpacing = 10;
      mcButtonWidth = 50;
      mcButtonHeight = 14;
      mcButtonSpacing = 4;
    var
      DialogUnits: TPoint;
      HorzMargin, VertMargin, HorzSpacing, VertSpacing, ButtonWidth,
      ButtonHeight, ButtonSpacing, ButtonCount, ButtonGroupWidth,
      IconTextWidth, IconTextHeight, X, ALeft: Integer;
      B, DefaultButton, CancelButton: TMsgDlgBtn;
      IconID: PChar;
      TextRect: TRect;
    begin
      Result := TMessageForm.CreateNew(Application);
      with Result do
      begin
        BiDiMode := Application.BiDiMode;
        BorderStyle := bsDialog;
        Canvas.Font := Font;
        DialogUnits := GetAveCharSize(Canvas);
        HorzMargin := MulDiv(mcHorzMargin, DialogUnits.X, 4);
        VertMargin := MulDiv(mcVertMargin, DialogUnits.Y, 8);
        HorzSpacing := MulDiv(mcHorzSpacing, DialogUnits.X, 4);
        VertSpacing := MulDiv(mcVertSpacing, DialogUnits.Y, 8);
        ButtonWidth := MulDiv(mcButtonWidth, DialogUnits.X, 4);
        for B := Low(TMsgDlgBtn) to High(TMsgDlgBtn) do
        begin
          if B in Buttons then
          begin
            if ButtonWidths[B] = 0 then
            begin
              TextRect := Rect(0,0,0,0);
              Windows.DrawText( canvas.handle,
                PChar(LoadResString(ButtonCaptions[B])), -1,
                TextRect, DT_CALCRECT or DT_LEFT or DT_SINGLELINE or
                DrawTextBiDiModeFlagsReadingOnly);
              with TextRect do ButtonWidths[B] := Right - Left + 8;
            end;
            if ButtonWidths[B] > ButtonWidth then
              ButtonWidth := ButtonWidths[B];
          end;
        end;
        ButtonHeight := MulDiv(mcButtonHeight, DialogUnits.Y, 8);
        ButtonSpacing := MulDiv(mcButtonSpacing, DialogUnits.X, 4);
        SetRect(TextRect, 0, 0, Screen.Width div 2, 0);
        DrawText(Canvas.Handle, PChar(Msg), Length(Msg)+1, TextRect,
          DT_EXPANDTABS or DT_CALCRECT or DT_WORDBREAK or
          DrawTextBiDiModeFlagsReadingOnly);
        IconID := IconIDs[DlgType];
        IconTextWidth := TextRect.Right;
        IconTextHeight := TextRect.Bottom;
        if IconID <> nil then
        begin
          Inc(IconTextWidth, 32 + HorzSpacing);
          if IconTextHeight < 32 then IconTextHeight := 32;
        end;
        ButtonCount := 0;
        for B := Low(TMsgDlgBtn) to High(TMsgDlgBtn) do
          if B in Buttons then Inc(ButtonCount);
        ButtonGroupWidth := 0;
        if ButtonCount <> 0 then
          ButtonGroupWidth := ButtonWidth * ButtonCount +
            ButtonSpacing * (ButtonCount - 1);
        ClientWidth := Max(IconTextWidth, ButtonGroupWidth) + HorzMargin * 2;
        ClientHeight := IconTextHeight + ButtonHeight + VertSpacing +
          VertMargin * 2;
        Left := (Screen.Width div 2) - (Width div 2);
        Top := (Screen.Height div 2) - (Height div 2);
        if DlgType <> mtCustom then
          Caption := LoadResString(Captions[DlgType]) else
          Caption := Application.Title;
        if IconID <> nil then
          with TImage.Create(Result) do
          begin
            Name := 'Image';
            Parent := Result;
            Picture.Icon.Handle := LoadIcon(0, IconID);
            SetBounds(HorzMargin, VertMargin, 32, 32);
          end;
        with TLabel.Create(Result) do
        begin
          Name := 'Message';
          Parent := Result;
          WordWrap := True;
          Caption := Msg;
          BoundsRect := TextRect;
          BiDiMode := Result.BiDiMode;
          ALeft := IconTextWidth - TextRect.Right + HorzMargin;
          if UseRightToLeftAlignment then
            ALeft := Result.ClientWidth - ALeft - Width;
          SetBounds(ALeft, VertMargin,
            TextRect.Right, TextRect.Bottom);
        end;
        if mbOk in Buttons then DefaultButton := mbOk else
          if mbYes in Buttons then DefaultButton := mbYes else
            DefaultButton := mbRetry;
        if mbCancel in Buttons then CancelButton := mbCancel else
          if mbNo in Buttons then CancelButton := mbNo else
            CancelButton := mbOk;
        X := (ClientWidth - ButtonGroupWidth) div 2;
        for B := Low(TMsgDlgBtn) to High(TMsgDlgBtn) do
          if B in Buttons then
            with TButton.Create(Result) do
            begin
              Name := ButtonNames[B];
              Parent := Result;
              Caption := LoadResString(ButtonCaptions[B]);
              ModalResult := ModalResults[B];
              if B = DefaultButton then Default := True;
              if B = CancelButton then Cancel := True;
              SetBounds(X, IconTextHeight + VertMargin + VertSpacing,
                ButtonWidth, ButtonHeight);
              Inc(X, ButtonWidth + ButtonSpacing);
              if B = mbHelp then
                OnClick := TMessageForm(Result).HelpButtonClick;
            end;
      end;
    end;
      

  3.   

    fuzhe2001(一刀) ,在一个单元里写showmessage,按ctrl,用鼠标左键点你写的showmessage,就会跳转到
    procedure ShowMessage(const Msg: string);
    begin
      ShowMessagePos(Msg, -1, -1);
    end;
    接着在ShowMessagePos上重复以上步骤,会跳转到
    function MessageDlgPos(const Msg: string; DlgType: TMsgDlgType;
      Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer): Integer;
    begin
      Result := MessageDlgPosHelp(Msg, DlgType, Buttons, HelpCtx, X, Y, '');
    end;
    以此类推
      

  4.   

    to ancient (ancient) 
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    谁知道showmessage是如何实现的,我是指它可以使调用它的过程在原地挂起。
    不调用底层的情况下可能实现这样的效果吗? thanx
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>试试api LockWindowUpdate
    function LockWindowUpdate(hWndLock: HWND): BOOL; stdcall;你在弹开自己的 messagebox 之前添入该句,锁住你要锁的窗体
    LockWindowUpdate(handle);
    application.create................要解锁,请归为0即可LockWindowUpdate(0);
    看看是不是你所想要的结果??:)
      

  5.   

    你做一个边框为dialog型的FORM,放一个按钮(button即可)然后指定其ModalResult为mrOk,再在form上放一label,再写一个函数:
    showmessageEx(Msg:string);
    var
      Form: TForm;
    begin
      form := TForm.create(nil);
      try
       form.label.caption := msg;
       form.width := label1.with + 40;
       form.showmodal;
      finally
       form.free;
      end;
    end;
      

  6.   

    这样说吧,如果不是在用delphi,而是在dos下用pascal进行编程,能很容易的实现showmessage吗(不考虑gui等细节,只说如何停止当前的程序,等待输入)?
      

  7.   

    >>这样说吧,如果不是在用delphi,而是在dos下用pascal进行编程,能很容易的实现showmessage吗
    程序中碰到readln语句,就会停下来,等待用户输入了。此时可以显示
    press any key to continue...
    用户按键后就会继续了。