2018年3月28日 星期三

InputBox ComboBox輸入視窗

//ComboBox輸入視窗
//Ex: InputBox('Caption', '血型', 'A;B;O;AB','A型;B型;O型;AB型', Result)

function fn_InputBox(const ACaption, APrompt: WideString; AListValue, AListDesc:WideString; var AResult:String): Boolean; overload; //ComboBox輸入視窗
var
  Form: TForm;
  Prompt:TLabel;
  Combobox: TCombobox;
  DialogUnits: TPoint;
  ButtonTop, ButtonWidth, ButtonHeight: Integer;
  j, iTop, iHeight:Integer;
  DescList, ValueList:TStringList;
  function GetAveCharSize(Canvas: TCanvas): TPoint;
  var
    I: Integer;
    Buffer: array[0..51] of Char;
  begin
    for I := 0 to 25 do Buffer[I] := Chr(I + Ord('A'));
    for I := 0 to 25 do Buffer[I + 26] := Chr(I + Ord('a'));
    GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));
    Result.X := Result.X div 52;
  end;
begin
  Result := False;
  ValueList := TStringList.Create;
  DescList := TStringList.Create;
  Form := TForm.Create(Application);
  with Form do
  begin
    try
      Font.Name := 'Arial';
      Font.Size := 12;
      Font.Style := [fsBold];
      Canvas.Font := Font;
      DialogUnits := GetAveCharSize(Canvas);
      BorderStyle := bsDialog;
      Caption := ACaption;
      ClientWidth := MulDiv(180, DialogUnits.X, 4);
      Position := poScreenCenter;

      Prompt := TLabel.Create(Form);
      with Prompt do
      begin
        Parent := Form;
        Caption := APrompt;
        Left := MulDiv(8, DialogUnits.X, 4);
        Top := MulDiv(8, DialogUnits.Y, 8);
        Constraints.MaxWidth := MulDiv(164, DialogUnits.X, 4);
        WordWrap := True;
      end;

      Combobox := TCombobox.Create(Form);
      with Combobox do
      begin
        Parent := Form;
        CharCase := ecUpperCase;
        Left := Prompt.Left;
        Top := Prompt.Top + Prompt.Height + 5;
        Width := MulDiv(164, DialogUnits.X, 4);

        ValueList.Assign(fn_SplitStr(';', AListValue));
        DescList.Assign(fn_SplitStr(';', AListDesc));
        Items.Clear;
        for j := 0 to DescList.Count-1 do
        begin
          if j >= ValueList.Count then
            Break;
          if (ValueList[j]+DescList[j])<>'' then
            Items.Add(ValueList[j]+ ' - ' +DescList[j]);
        end;
        ItemIndex := ValueList.IndexOf(AResult);

        iTop := Top;
        iHeight := Height;
      end;

      ButtonTop := iTop + iHeight + 15;
      ButtonWidth := MulDiv(50, DialogUnits.X, 4);
      ButtonHeight := MulDiv(14, DialogUnits.Y, 8);
      with TButton.Create(Form) do
      begin
        Parent := Form;
        Caption := '確定';
        ModalResult := mrOk;
        Default := True;
        SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth,
          ButtonHeight);
      end;

      with TButton.Create(Form) do
      begin
        Parent := Form;
        Caption := '取消';
        ModalResult := mrCancel;
        Cancel := True;
        SetBounds(MulDiv(92, DialogUnits.X, 4), ButtonTop, ButtonWidth,
          ButtonHeight);
        Form.ClientHeight := Top + Height + 13;
      end;
      if ShowModal = mrOk then
      begin
        AResult := '';
        if Combobox.ItemIndex<>-1 then
          AResult := ValueList[Combobox.ItemIndex];
        Result := True;
      end;
    finally
      FreeAndNil(ValueList);
      FreeAndNil(DescList);
      Form.Free;
    end;
  end;
end;

InputBox DateTime輸入視窗

//DateTime 輸入視窗
function fn_InputBox(const ACaption, APrompt: WideString;var ADatetime: TDatetime): Boolean;
var
  Form: TForm;
  Prompt: TLabel;
  MonthCalendar:TMonthCalendar;
  DialogUnits: TPoint;
  ButtonTop, ButtonWidth, ButtonHeight: Integer;
  iTop, iHeight:Integer;
  APoint:TPoint;
  function GetAveCharSize(Canvas: TCanvas): TPoint;
  var
    I: Integer;
    Buffer: array[0..51] of Char;
  begin
    for I := 0 to 25 do Buffer[I] := Chr(I + Ord('A'));
    for I := 0 to 25 do Buffer[I + 26] := Chr(I + Ord('a'));
    GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));
    Result.X := Result.X div 52;
  end;
begin
  Result := False;
  Form := TForm.Create(Application);
  with Form do
  begin
    try
      Font.Name := 'Arial';
      Font.Size := 12;
      Font.Style := [fsBold];
      Canvas.Font := Font;
      DialogUnits := GetAveCharSize(Canvas);
      BorderStyle := bsDialog;
      Caption := ACaption;
      ClientWidth := MulDiv(180, DialogUnits.X, 4);
      //Position := poScreenCenter;

      APoint := Screen.ActiveControl.ClientToScreen(Point(0, Screen.ActiveControl.ClientHeight));
      Left := APoint.X;
      Top := APoint.Y;
      Position := poDesigned;

      Prompt := TLabel.Create(Form);
      with Prompt do
      begin
        Parent := Form;
        Caption := APrompt;
        Left := MulDiv(8, DialogUnits.X, 4);
        Top := MulDiv(8, DialogUnits.Y, 8);
        Constraints.MaxWidth := MulDiv(164, DialogUnits.X, 4);
        WordWrap := True;
      end;

      with TComboBox.Create(Form) do
      begin
        Parent := Form;
        DropDownCount := 9;
        Top := Prompt.Top;
        Left := MulDiv(45, DialogUnits.X, 4);
        Style := StdCtrls.csDropDownList;
        Items.Add('');
        Items.Add('昨日');
        Items.Add('今日');
        Items.Add('上月初');
        Items.Add('上月底');
        Items.Add('月初');
        Items.Add('月底');
        Items.Add('年初');
        Items.Add('年底');
        OnChange := TVirtualClass.pr_ComboBox_OnChange;
      end;

      MonthCalendar := TMonthCalendar.Create(Form);
      with MonthCalendar do
      begin
        Parent := Form;
        AutoSize := False;
        Left := Prompt.Left;
        Top := Prompt.Top + Prompt.Height + 10;
        Width := MulDiv(164, DialogUnits.X, 4);
        Height := 213;
        MonthCalendar.Date := ADatetime;
        iTop := Top;
        iHeight := Height;
      end;

      ButtonTop := iTop + iHeight + 15;
      ButtonWidth := MulDiv(50, DialogUnits.X, 4);
      ButtonHeight := MulDiv(14, DialogUnits.Y, 8);

      with TButton.Create(Form) do
      begin
        Parent := Form;
        Caption := '確定';
        ModalResult := mrOk;
        Default := True;
        SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth,
          ButtonHeight);
      end;

      with TButton.Create(Form) do
      begin
        Parent := Form;
        Caption := '取消';
        ModalResult := mrCancel;
        Cancel := True;
        SetBounds(MulDiv(92, DialogUnits.X, 4), ButtonTop, ButtonWidth,
          ButtonHeight);
        Form.ClientHeight := Top + Height + 13;
      end;

      if ShowModal = mrOk then
      begin
        ADatetime := MonthCalendar.Date;
        Result := True;
      end;
    finally
      Form.Free;
    end;
  end;
end;

InputBox String輸入視窗

//
function fn_InputBox(const ACaption, APrompt: WideString;var AString: String): Boolean;
var
  Form: TForm;
  Prompt: TLabel;
  Edit: TEdit;
  DialogUnits: TPoint;
  ButtonTop, ButtonWidth, ButtonHeight: Integer;
  iTop, iHeight:Integer;
  function GetAveCharSize(Canvas: TCanvas): TPoint;
  var
    I: Integer;
    Buffer: array[0..51] of Char;
  begin
    for I := 0 to 25 do Buffer[I] := Chr(I + Ord('A'));
    for I := 0 to 25 do Buffer[I + 26] := Chr(I + Ord('a'));
    GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));
    Result.X := Result.X div 52;
  end;
begin
  Result := False;
  Form := TForm.Create(Application);
  with Form do
  begin
    try
      Font.Name := 'Arial';
      Font.Size := 12;
      Font.Style := [fsBold];
      Canvas.Font := Font;
      DialogUnits := GetAveCharSize(Canvas);
      BorderStyle := bsDialog;
      Caption := ACaption;
      ClientWidth := MulDiv(180, DialogUnits.X, 4);
      Position := poScreenCenter;

      Prompt := TLabel.Create(Form);
      with Prompt do
      begin
        Parent := Form;
        Caption := APrompt;
        Left := MulDiv(8, DialogUnits.X, 4);
        Top := MulDiv(8, DialogUnits.Y, 8);
        Constraints.MaxWidth := MulDiv(164, DialogUnits.X, 4);
        WordWrap := True;
      end;

      Edit := TEdit.Create(Form);
      with Edit do
      begin
        Parent := Form;
        CharCase := ecUpperCase;
        Left := Prompt.Left;
        Top := Prompt.Top + Prompt.Height + 5;
        Width := MulDiv(164, DialogUnits.X, 4);
        MaxLength := 255;
        Text := AString;
        iTop := Top;
        iHeight := Height;
        Color := $00F5D8BC;
        SelectAll;
      end;

      ButtonTop := iTop + iHeight + 15;
      ButtonWidth := MulDiv(50, DialogUnits.X, 4);
      ButtonHeight := MulDiv(14, DialogUnits.Y, 8);
      with TButton.Create(Form) do
      begin
        Parent := Form;
        Caption := '確定';
        ModalResult := mrOk;
        Default := True;
        SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth,
          ButtonHeight);
      end;
      with TButton.Create(Form) do
      begin
        Parent := Form;
        Caption := '取消';
        ModalResult := mrCancel;
        Cancel := True;
        SetBounds(MulDiv(92, DialogUnits.X, 4), ButtonTop, ButtonWidth,
          ButtonHeight);
        Form.ClientHeight := Top + Height + 13;
      end;
      if ShowModal = mrOk then
      begin
        AString := Edit.Text;
        //
        Result := True;
      end;
    finally
      Form.Free;
    end;
  end;
end;

日期相關的函式

Uses SysUtils, DateUtils;

//取得系統日期格式
procedure GetLocaleFormatSettings(LCID: Integer; var FormatSettings: TFormatSettings);

//時間
function Time: TDateTime;

//日期時間
function Now: TDateTime;

//今天
function Today: TDateTime;

//昨天
function Yesterday: TDateTime;

//明天
function Tomorrow: TDateTime;

//目前年份
function CurrentYear: Word;

//取DateTime年份
function YearOf(const AValue: TDateTime): Word;

//取DateTime月份
function MonthOf(const AValue: TDateTime): Word;

//取DateTime週數
function WeekOf(const AValue: TDateTime): Word;                     

//取DateTime日期
function DayOf(const AValue: TDateTime): Word;

//取DateTime小時數
function HourOf(const AValue: TDateTime): Word;

//取DateTime分鐘數
function MinuteOf(const AValue: TDateTime): Word;

//取DateTime秒數
function SecondOf(const AValue: TDateTime): Word;

//月份增減
function IncMonth(const DateTime: TDateTime; NumberOfMonths: Integer = 1): TDateTime; 

//年度增減
function IncYear(const AValue: TDateTime;  const ANumberOfYears: Integer = 1): TDateTime;

//週數增減
function IncWeek(const AValue: TDateTime;  const ANumberOfWeeks: Integer = 1): TDateTime;

//日期增減
function IncDay(const AValue: TDateTime;  const ANumberOfDays: Integer = 1): TDateTime;

//時數增減
function IncHour(const AValue: TDateTime;  const ANumberOfHours: Int64 = 1): TDateTime;

//分鐘增減
function IncMinute(const AValue: TDateTime;  const ANumberOfMinutes: Int64 = 1): TDateTime;

//秒數增減
function IncSecond(const AValue: TDateTime;  const ANumberOfSeconds: Int64 = 1): TDateTime;

//是否為潤年
function IsLeapYear(Year: Word): Boolean;

//以指定的日期格式輸出字串
function FormatDateTime(const Format: string; DateTime: TDateTime): string;
function FormatDateTime(const Format: string; DateTime: TDateTime; const FormatSettings: TFormatSettings):

//AM/PM
function IsPM(const AValue: TDateTime): Boolean;

//檢查日期的正確性
function IsValidDate(const AYear, AMonth, ADay: Word): Boolean;

//年度第一天(年初)
function StartOfTheYear(const AValue: TDateTime): TDateTime;
function StartOfAYear(const AYear: Word): TDateTime;

//年度最後一天(年底)
function EndOfTheYear(const AValue: TDateTime): TDateTime;
function EndOfAYear(const AYear: Word): TDateTime;

//月份第一天(月初)
function StartOfTheMonth(const AValue: TDateTime): TDateTime;
function StartOfAMonth(const AYear, AMonth: Word): TDateTime;

//月份最後一天(月底)
function EndOfTheMonth(const AValue: TDateTime): TDateTime;
function EndOfAMonth(const AYear, AMonth: Word): TDateTime;

//週數第一天
function StartOfTheWeek(const AValue: TDateTime): TDateTime;

//週數最後一天
function EndOfTheWeek(const AValue: TDateTime): TDateTime; 

//日期區間的天數
function DaysBetween(const ANow, AThen: TDateTime): Integer;

取檔案日期

function fn_Get_FileDatetime(AFileName:String):TDatetime;
var
  iFileAge:Integer;
begin
  iFileAge := FileAge(AFileName);
  Result := FileDateToDatetime(iFileAge);
end;

2018年3月27日 星期二

檔案文件相關的函式

Uses SysUtils;

//取檔案名稱
//Ex: C:\Test\NoName.txt -> NoName.txt
function ExtractFileName(const FileName: string): string;

//取檔案副檔名
//Ex: C:\Test\NoName.txt -> .txt
function ExtractFileExt(const FileName: string): string;

//取檔案所在磁碟代號
//Ex: C:\Test\NoName.txt -> C:
function ExtractFileDrive(const FileName: string): string;

//取檔案路徑
//Ex: C:\Test\NoName.txt -> C:\Test\
function ExtractFilePath(const FileName: string): string;

//取檔案目錄
//Ex: C:\Test\NoName.txt -> C:\Test
function ExtractFileDir(const FileName: string): string;

//變更副檔案名稱
//Ex: C:\Test\NoName.txt -> C:\Test\NoName.xxx
function ChangeFileExt(const FileName, Extension: string): string;

//取得檔案目錄路徑 (目錄後面加斜線符號)
//Ex: C:\Test -> C:\Test\
function IncludeTrailingPathDelimiter(const S: string): string;
function IncludeTrailingBackslash(const S: string): string;

//取得檔案目錄路徑 (目錄後面去除斜線符號)
//Ex: C:\Test\ -> C:\Test
function ExcludeTrailingPathDelimiter(const S: string): string;
function ExcludeTrailingBackslash(const S: string): string;

//檢查檔案是否存在
function FileExists(const FileName: string): Boolean;

//檢查目錄是否存在
function DirectoryExists(const Directory: string): Boolean;

//產生多層資料夾
//Ex: ForceDirectories('c:\a\b\c')
function ForceDirectories(Dir: string): Boolean;

//檢查檔案是否唯讀
function FileIsReadOnly(const FileName: string): Boolean;

//取得檔案屬性
function FileGetAttr(const FileName: string): Integer;

//設定檔案屬性
function FileSetAttr(const FileName: string; Attr: Integer): Integer;

//設定唯讀檔案
function FileSetReadOnly(const FileName: string; ReadOnly: Boolean): Boolean;

//刪除檔案
function DeleteFile(const FileName: string): Boolean;

//變更檔案名稱
function RenameFile(const OldName, NewName: string): Boolean;

//取得磁碟空間
function DiskSize(Drive: Byte): Int64;

//取得目前所在目錄
function GetCurrentDir: string;

//設定目前所在目錄
function SetCurrentDir(const Dir: string): Boolean;

//建立目錄
function CreateDir(const Dir: string): Boolean;

//移除目錄
function RemoveDir(const Dir: string): Boolean;

//----------------------------------------------------------------------------------------------------------------
//取檔案日期
//----------------------------------------------------------------------------------------------------------------
function fn_Get_FileDatetime(AFileName:String):TDatetime;
var
  iFileAag:Integer;
begin
  iFileAag := FileAge(AFileName);
  Result := FileDateToDatetime(iFileAge);
end;

//----------------------------------------------------------------------------------------------------------------
//取檔案清單
//----------------------------------------------------------------------------------------------------------------
function fn_Get_FileList(APath:String; AFullPath:Boolean=False; ASearchSubPath:Boolean=False):TStringList;
var SearchRec: TSearchRec;
  Status: Integer;
  sFileList:TStringList;
  sPath:String;
begin
  sPath := '';
  if AFullPath then
    sPath := IncludeTrailingPathDelimiter(APath); // Ex: C:\temp -> C:\temp\
  sFileList := TStringList.Create;
  Status := FindFirst(APath+'\*.*', faAnyFile, SearchRec);
  try
    while Status = 0 do
    begin
      if ((SearchRec.Attr and faHidden)<>faHidden) and //非隱藏檔
        ((SearchRec.Attr and faSysFile)<>faSysFile) and //非系統檔
        (SearchRec.Name <> '.') and
        (SearchRec.Name <> '..') then
      begin
        if ((SearchRec.Attr and faDirectory) = faDirectory) then //目錄
        begin
          if ASearchSubPath then
            sFileList.AddStrings(fn_Get_FileList(APath+'\'+SearchRec.Name, AFullPath, ASearchSubPath))
        end
        else
          sFileList.Add(sPath+SearchRec.Name);
      end;
      Status := FindNext(SearchRec);
    end;
  Finally
    FindClose(SearchRec);
  end;
  Result := sFileList;
end;

//----------------------------------------------------------------------------------------------------------------
//檔案被使用中
//----------------------------------------------------------------------------------------------------------------
function fn_FileInUse(fName: string): boolean;
var
  HFileRes: HFILE;
begin
  Result := false;
  if not FileExists(fName) then
    exit;
  HFileRes := CreateFile(pchar(fName), GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  Result := (HFileRes = INVALID_HANDLE_VALUE);
  if not Result then
    CloseHandle(HFileRes);
end;

//----------------------------------------------------------------------------------------------------------------
//建立資料夾
//----------------------------------------------------------------------------------------------------------------
procedure pr_CreateDir(ADir:String);
var sFolderList:TStringList;
  sDrive, sFolder:String;
  i:Integer;
begin
  sFolderList := TStringList.Create;
  ADir := ExcludeTrailingPathDelimiter(ADir); //Ex: C:\Temp\A\1\ -> C:\Temp\A\1
  sDrive := ExtractFileDrive(ADir)+'\'; //Ex: C:\
  //
  sFolderList.Add(ADir);
  sFolder := ADir;
  while True do
  begin
    sFolder := ExtractFileDir(sFolder);
    if sFolder=sDrive then
      Break;
    sFolderList.Insert(0, sFolder);
  end;
  //
  for i:=0 to sFolderList.Count-1 do
  begin
    if not DirectoryExists(sFolderList[i]) then
      CreateDir(sFolderList[i]);
  end;
  FreeAndNil(sFolderList);
end;

//----------------------------------------------------------------------------------------------------------------
//檔案複製/搬移 (含子資料夾)
//----------------------------------------------------------------------------------------------------------------
procedure pr_CopyFile(ASourceFile, ATargetPath:String; ASearchSubPath:Boolean=False; AMoveFile:Boolean=False);
var SearchRec: TSearchRec;
  Status: Integer;
  sSourcePath, sTargetPath, sTargetDir,
  sSearchFileName, sTargetFileName, sFileName:String;
begin
  sFileName := ExtractFileName(ASourceFile);
  sSourcePath := ExtractFilePath(ASourceFile);
  sTargetPath := IncludeTrailingPathDelimiter(ATargetPath);
  sTargetDir := ExcludeTrailingPathDelimiter(ATargetPath);
  if CompareText(sSourcePath, sTargetPath)=0 then
    Exit;
  //
  pr_CreateDir(sTargetDir); //建立目的資料夾
  //
  Status := FindFirst(ASourceFile, faAnyFile, SearchRec);
  try
    while Status = 0 do
    begin
      if ((SearchRec.Attr and faHidden)<>faHidden) and //非隱藏檔
        ((SearchRec.Attr and faSysFile)<>faSysFile) and //非系統檔
        (SearchRec.Name <> '.') and
        (SearchRec.Name <> '..') then
      begin
        sSearchFileName := sSourcePath + SearchRec.Name;
        if ((SearchRec.Attr and faDirectory) = faDirectory) then //目錄
        begin
          if ASearchSubPath then
          begin
            if CompareText(sSearchFileName, sTargetDir)<>0 then
            begin
              pr_CopyFile(sSearchFileName+'\'+sFileName, sTargetPath+SearchRec.Name, ASearchSubPath);
            end;
          end;
        end
        else if not fn_FileInUse(sSearchFileName) then
        begin
          sTargetFileName := sTargetPath + SearchRec.Name;
          if AMoveFile then
            MoveFile(PWideChar(sSearchFileName), PWideChar(sTargetFileName)) //搬移
          else
            CopyFile(PWideChar(sSearchFileName), PWideChar(sTargetFileName), False); //複製
        end;
      end;
      Status := FindNext(SearchRec);
    end;
  Finally
    FindClose(SearchRec);
  end;
end;






2018年3月26日 星期一

Runtime error 217 at 004539BD

Delphi 專案

  Project -> Options
  [Link with runtime packages] 設成 False

  一樣還是出現 Runtime error 217 at xxxxxxxx的訊息

  結果發現是專案裡 Uses 了其他的 Unit File,Unit File裡引用了其他資源文件導至錯誤 !

2018年3月21日 星期三

Runtime error 217 at 5015D5F4 (Windows 2016)

Delphi 編譯後的執行檔安裝到Windows2016中執行,出現 Runtime error 217 at xxxxxxxx

處理辦法:
  執行檔滑鼠右鍵 > 內容,使用Run compatibility troubleshooter功能可以排除狀況



2018年3月7日 星期三

《遙控器學習設定》一支bbtv機上盒遙控器就能搞定開關電視、轉台、調整音量

《遙控器學習設定》一支bbtv機上盒遙控器就能搞定開關電視、轉台、調整音量

設定前請先準備好家中電視遙控器與bbTV遙控器
並確認您的bbTV遙控器是屬於下圖ABC的哪一隻
確認之後,並再照著此遙控器操作步驟進行設定




【A遙控器使用說明】


【B遙控器使用說明】


【C遙控器使用說明】


轉貼至: http://www.cdtv.com.tw/zh_TW/news_content/id/77

2018年3月5日 星期一

MessageBox

函數原型及參數
 function MessageBox(hWnd: HWND; TextCaption: PChar; Type: Word): Integer;

hWnd:對話框父窗口句柄,對話框顯示在Delphi窗體內,可使用窗體的Handle屬性,否則可用0,使其直接作為桌面窗口的子窗口。

Text:欲顯示的信息字符串。

Caption:對話框標題字符串。

Type:對話框類型常量。

按鈕組合常量
   MB_OK = $00000000;                                     //一個確定按鈕
   MB_OKCANCEL = $00000001;                     //一個確定按鈕,取消按鈕
   MB_ABORTRETRYIGNORE = $00000002;  //一個異常終止按鈕,重試按鈕,忽略按鈕
   MB_YESNOCANCEL = $00000003;             //一個是按鈕,一個否按鈕,一個取消按鈕
   MB_YESNO = $00000004;                             //一個是按鈕,一個否按鈕
   MB_RETRYCANCEL = $00000005;              //一個重試按鈕,一個取消按鈕

預設按鈕
   MB_DEFBUTTON1 = $00000000;           //第一個按鈕為缺省按鈕
   MB_DEFBUTTON2 = $00000100;           //第二個按鈕為缺省按鈕
   MB_DEFBUTTON3 = $00000200;           //第三個按鈕為缺省按鈕
   MB_DEFBUTTON4 = $00000300;           //第四個按鈕為缺省按鈕

圖標常量
   MB_ICONHAND = $00000010;                                        //「×」號圖標
   MB_ICONQUESTION = $00000020;                              //「?」號圖標
   MB_ICONEXCLAMATION = $00000030;                      //「!」號圖標
   MB_ICONASTERISK = $00000040;                                //「i」圖標
   MB_USERICON = $00000080;                                         //用戶圖標
   MB_ICONWARNING = MB_ICONEXCLAMATION;    //「!」號圖標
   MB_ICONERROR = MB_ICONHAND;                          //「×」號圖標
   MB_ICONINFORMATION = MB_ICONASTERISK;    //「i」圖標
   MB_ICONSTOP = MB_ICONHAND;                             //「×」號圖標

運行模式常量
   MB_APPLMODAL = $00000000;     
      //應用程序模式,在未結束對話框前也能切換到另一應用程序
   MB_SYSTEMMODAL = $00001000;     
      //系統模式,必須結束對話框後,才能做其他操作
   MB_TASKMODAL = $00002000;       
      //任務模式,在未結束對話框前也能切換到另一應用程序
   MB_HELP = $00004000;           
      //Help Button

函數返回值
   0                        //對話框建立失敗
   idOk = 1            //按確定按鈕
   idCancel = 2      //按取消按鈕
   idAbout = 3       //按異常終止按鈕
   idRetry = 4        //按重試按鈕
   idIgnore = 5      //按忽略按鈕
   idYes = 6           //按是按鈕
   idNo = 7            //按否按鈕

例:
  Result := MessageBox(Handle, 'Test', 'Message', MB_OK);
  Result := MessageBox(Handle, 'Exit ?', 'Question', MB_ICONQUESTION+MB_YESNO+MB_DEFBUTTON2);


轉貼至 http://chengyan35.pixnet.net/blog/post/142390734-[delphi]delphi中的messagebox用法