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.
    
    
  • 相关阅读:
    每日英语:Italian town fighting for its life over polluting Ilva steelworks
    SpringBoot + Kafka + ELK 完成海量日志收集(超详细)
    如何使用 Java 生成二维码?
    xyntservice
    windows service 与GUI窗口的实现
    一个可以查看HTML网页上密码框的程序(附源码)
    vss6 forgot admin password
    vs2005's addin folder
    javascript tips
    html中使用imagemap
  • 原文地址:https://www.cnblogs.com/zhuzhongxing/p/14147084.html
Copyright © 2011-2022 走看看