MessageBox 简单模板封装

unit UOptionPane;

interface

uses
    Windows;

const
    TITLE_T = ' 提示消息 ';
    TITLE_W = ' 警告消息 ';
    TITLE_E = ' 错误消息 ';
    TITLE_Q = ' 询问消息 ';

type
    TOptionPane = class(TObject)
    public
        class function ShowTips(text: string; title: string = TITLE_T): Integer; overload;
        class function ShowTips(owner: HWND; text: string; title: string = TITLE_T): Integer; overload;
        class function ShowTipsYesNo(text: string; title: string = TITLE_T): Integer; overload;
        class function ShowTipsYesNo(owner: HWND; text: string; title: string = TITLE_T): Integer; overload;
        class function ShowTipsYesNoCancel(text: string; title: string = TITLE_T): Integer; overload;
        class function ShowTipsYesNoCancel(owner: HWND; text: string; title: string = TITLE_T): Integer; overload;
        class function ShowWarning(text: string; title: string = TITLE_W): Integer; overload;
        class function ShowWarning(owner: HWND; text: string; title: string = TITLE_W): Integer; overload;
        class function ShowWarningYesNo(text: string; title: string = TITLE_W): Integer; overload;
        class function ShowWarningYesNo(owner: HWND; text: string; title: string = TITLE_W): Integer; overload;
        class function ShowWarningYesNoCancel(text: string; title: string = TITLE_W): Integer; overload;
        class function ShowWarningYesNoCancel(owner: HWND; text: string; title: string = TITLE_W): Integer; overload;
        class function ShowError(text: string; title: string = TITLE_E): Integer; overload;
        class function ShowError(owner: HWND; text: string; title: string = TITLE_E): Integer; overload;
        class function ShowErrorYesNo(text: string; title: string = TITLE_E): Integer; overload;
        class function ShowErrorYesNo(owner: HWND; text: string; title: string = TITLE_E): Integer; overload;
        class function ShowErrorYesNoCancel(text: string; title: string = TITLE_E): Integer; overload;
        class function ShowErrorYesNoCancel(owner: HWND; text: string; title: string = TITLE_E): Integer; overload;
        class function ShowConfirm(text: string; title: string = TITLE_Q): Boolean; overload;
        class function ShowConfirm(owner: HWND; text: string; title: string = TITLE_Q): Boolean; overload;
        class function ShowConfirmYesNo(text: string; title: string = TITLE_Q): Integer; overload;
        class function ShowConfirmYesNo(owner: HWND; text: string; title: string = TITLE_Q): Integer; overload;
        class function ShowConfirmYesNoCancel(text: string; title: string = TITLE_Q): Integer; overload;
        class function ShowConfirmYesNoCancel(owner: HWND; text: string; title: string = TITLE_Q): Integer; overload;
    end;

implementation

class function TOptionPane.ShowTips(text: string; title: string = TITLE_T): Integer;
begin
    Result := ShowTips(0, text, title);
end;

class function TOptionPane.ShowTips(owner: HWND; text: string; title: string = TITLE_T): Integer;
begin
    Result := MessageBox(owner, PChar(text), PChar(title), MB_OK + MB_ICONINFORMATION);
end;

class function TOptionPane.ShowTipsYesNo(text: string; title: string = TITLE_T): Integer;
begin
    Result := ShowTipsYesNo(0, text, title);
end;

class function TOptionPane.ShowTipsYesNo(owner: HWND; text: string; title: string = TITLE_T): Integer;
begin
    Result := MessageBox(owner, PChar(text), PChar(title), MB_YESNO + MB_ICONINFORMATION);
end;

class function TOptionPane.ShowTipsYesNoCancel(text: string; title: string = TITLE_T): Integer;
begin
    Result := ShowTipsYesNoCancel(0, text, title);
end;

class function TOptionPane.ShowTipsYesNoCancel(owner: HWND; text: string; title: string = TITLE_T): Integer;
begin
    Result := MessageBox(owner, PChar(text), PChar(title), MB_YESNOCANCEL + MB_ICONINFORMATION);
end;

////////////////////////////////////////////////////////////////////////////////

class function TOptionPane.ShowWarning(text: string; title: string = TITLE_W): Integer;
begin
    Result := ShowWarning(0, text, title);
end;

class function TOptionPane.ShowWarning(owner: HWND; text: string; title: string = TITLE_W): Integer;
begin
    Result := MessageBox(owner, PChar(text), PChar(title), MB_OK + MB_ICONWARNING);
end;

class function TOptionPane.ShowWarningYesNo(text: string; title: string = TITLE_W): Integer;
begin
    Result := ShowWarningYesNo(0, text, title);
end;

class function TOptionPane.ShowWarningYesNo(owner: HWND; text: string; title: string = TITLE_W): Integer;
begin
    Result := MessageBox(owner, PChar(text), PChar(title), MB_YESNO + MB_ICONWARNING);
end;

class function TOptionPane.ShowWarningYesNoCancel(text: string; title: string = TITLE_W): Integer;
begin
    Result := ShowWarningYesNoCancel(0, text, title);
end;

class function TOptionPane.ShowWarningYesNoCancel(owner: HWND; text: string; title: string = TITLE_W): Integer;
begin
    Result := MessageBox(owner, PChar(text), PChar(title), MB_YESNOCANCEL + MB_ICONWARNING);
end;

////////////////////////////////////////////////////////////////////////////////

class function TOptionPane.ShowError(text: string; title: string = TITLE_E): Integer;
begin
    Result := ShowError(0, text, title);
end;

class function TOptionPane.ShowError(owner: HWND; text: string; title: string = TITLE_E): Integer;
begin
    Result := MessageBox(owner, PChar(text), PChar(title), MB_OK + MB_ICONERROR);
end;

class function TOptionPane.ShowErrorYesNo(text: string; title: string = TITLE_E): Integer;
begin
    Result := ShowErrorYesNo(0, text, title);
end;

class function TOptionPane.ShowErrorYesNo(owner: HWND; text: string; title: string = TITLE_E): Integer;
begin
    Result := MessageBox(owner, PChar(text), PChar(title), MB_YESNO + MB_ICONERROR);
end;

class function TOptionPane.ShowErrorYesNoCancel(text: string; title: string = TITLE_E): Integer;
begin
    Result := ShowErrorYesNoCancel(0, text, title);
end;

class function TOptionPane.ShowErrorYesNoCancel(owner: HWND; text: string; title: string = TITLE_E): Integer;
begin
    Result := MessageBox(owner, PChar(text), PChar(title), MB_YESNOCANCEL + MB_ICONERROR);
end;

////////////////////////////////////////////////////////////////////////////////

class function TOptionPane.ShowConfirm(text: string; title: string = TITLE_Q): Boolean;
begin
    Result := ShowConfirm(0, text, title);
end;

class function TOptionPane.ShowConfirm(owner: HWND; text: string; title: string = TITLE_Q): Boolean;
begin
    Result := idYes = MessageBox(owner, PChar(text), PChar(title), MB_YESNO + MB_ICONQUESTION);
end;

class function TOptionPane.ShowConfirmYesNo(text: string; title: string = TITLE_Q): Integer;
begin
    Result := ShowConfirmYesNo(0, text, title);
end;

class function TOptionPane.ShowConfirmYesNo(owner: HWND; text: string; title: string = TITLE_Q): Integer;
begin
    Result := MessageBox(owner, PChar(text), PChar(title), MB_YESNO + MB_ICONQUESTION);
end;

class function TOptionPane.ShowConfirmYesNoCancel(text: string; title: string = TITLE_Q): Integer;
begin
    Result := ShowConfirmYesNoCancel(0, text, title);
end;

class function TOptionPane.ShowConfirmYesNoCancel(owner: HWND; text: string; title: string = TITLE_Q): Integer;
begin
    Result := MessageBox(owner, PChar(text), PChar(title), MB_YESNOCANCEL + MB_ICONQUESTION);
end;

////////////////////////////////////////////////////////////////////////////////

end.


内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/zhuzhongxing/p/14147084.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!