zoukankan      html  css  js  c++  java
  • 【Delphi】Dialogs.TOptionPane(MessageBox 简单模板封装)

    MessageBox 简单模板封装

    unit Dialogs.OptionPane;
    
    interface
    
    uses
        Winapi.Windows, Vcl.Dialogs;
    
    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(GetActiveWindow, 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);
        // Result := TaskMessageDlg(title, text, mtInformation, [mbOK], 0);
    end;
    
    class function TOptionPane.ShowTipsYesNo(text: string; title: string = TITLE_T): Integer;
    begin
        Result := ShowTipsYesNo(GetActiveWindow, 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);
        // Result := TaskMessageDlg(title, text, mtInformation, [mbYes, mbNo], 0);
    end;
    
    class function TOptionPane.ShowTipsYesNoCancel(text: string; title: string = TITLE_T): Integer;
    begin
        Result := ShowTipsYesNoCancel(GetActiveWindow, 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);
        // Result := TaskMessageDlg(title, text, mtInformation, [mbYes, mbNo, mbCancel], 0);
    end;
    
    ////////////////////////////////////////////////////////////////////////////////
    
    class function TOptionPane.ShowWarning(text: string; title: string = TITLE_W): Integer;
    begin
        Result := ShowWarning(GetActiveWindow, 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);
        // Result := TaskMessageDlg(title, text, mtWarning, [mbOK], 0);
    end;
    
    class function TOptionPane.ShowWarningYesNo(text: string; title: string = TITLE_W): Integer;
    begin
        Result := ShowWarningYesNo(GetActiveWindow, 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);
        // Result := TaskMessageDlg(title, text, mtWarning, [mbYes, mbNo], 0);
    end;
    
    class function TOptionPane.ShowWarningYesNoCancel(text: string; title: string = TITLE_W): Integer;
    begin
        Result := ShowWarningYesNoCancel(GetActiveWindow, 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);
        // Result := TaskMessageDlg(title, text, mtWarning, [mbYes, mbNo, mbCancel], 0);
    end;
    
    ////////////////////////////////////////////////////////////////////////////////
    
    class function TOptionPane.ShowError(text: string; title: string = TITLE_E): Integer;
    begin
        Result := ShowError(GetActiveWindow, 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);
        // Result := TaskMessageDlg(title, text, mtError, [mbOK], 0);
    end;
    
    class function TOptionPane.ShowErrorYesNo(text: string; title: string = TITLE_E): Integer;
    begin
        Result := ShowErrorYesNo(GetActiveWindow, 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);
        // Result := TaskMessageDlg(title, text, mtError, [mbYes, mbNo], 0);
    end;
    
    class function TOptionPane.ShowErrorYesNoCancel(text: string; title: string = TITLE_E): Integer;
    begin
        Result := ShowErrorYesNoCancel(GetActiveWindow, 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);
        // Result := TaskMessageDlg(title, text, mtError, [mbYes, mbNo, mbCancel], 0);
    end;
    
    ////////////////////////////////////////////////////////////////////////////////
    
    class function TOptionPane.ShowConfirm(text: string; title: string = TITLE_Q): Boolean;
    begin
        Result := ShowConfirm(GetActiveWindow, 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);
        // Result := idYes = TaskMessageDlg(title, text, mtConfirmation, [mbYes, mbNo], 0);
    end;
    
    class function TOptionPane.ShowConfirmYesNo(text: string; title: string = TITLE_Q): Integer;
    begin
        Result := ShowConfirmYesNo(GetActiveWindow, 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);
        // Result := TaskMessageDlg(title, text, mtConfirmation, [mbYes, mbNo], 0);
    end;
    
    class function TOptionPane.ShowConfirmYesNoCancel(text: string; title: string = TITLE_Q): Integer;
    begin
        Result := ShowConfirmYesNoCancel(GetActiveWindow, 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);
        // Result := TaskMessageDlg(title, text, mtConfirmation, [mbYes, mbNo, mbCancel], 0);
    end;
    
    ////////////////////////////////////////////////////////////////////////////////
    
    end.
    
    
  • 相关阅读:
    和时间做朋友:你一定要学的高效时间管理术
    助推:如何做出有关健康、财富与幸福的最佳决策(2017年诺贝尔经济学奖获得者理查德·泰勒作品)
    看透 : 解密身体语言隐藏的密码
    成为独角兽:海盗、梦想家、创新者如何开创并主宰新品类
    极简法则:从苹果到优步的深层简化工具
    高效15法则:谷歌、苹果都在用的深度工作发
    成功与运气:好运与精英社会的神话
    2星|《成长企业的法则》:尝试总结成功企业的模式,但是洞察力不够。
    3星|《OKR:源于英特热和谷歌的目标管理利器》:OKR原理、实施手册、实施过的公司的访谈
    gedit如何使用代码片段
  • 原文地址:https://www.cnblogs.com/zhuzhongxing/p/14147084.html
Copyright © 2011-2022 走看看