Wolfgang Chien's Homepage | Delphi學習筆記 - 問答篇 |
呼叫MessageDlg時所顯示對話盒中之訊息文字, 請問如何改變其大小?
![]() |
如果有 VCL 原始碼, 那可以直接修改 VCL 原始程式(修改的步驟容後說明) |
![]() |
如果您沒有VCL的原始程式, 那可以改用 Application.MessageBox(),
使用時與一般的WinAPI相差不多, 以下有一個包裝過的函式. (* -------------------------------------------------- *) (* MsgBox('提示文字', '標題', ID_Flat) 訊息視窗 (* ============================================ (* 第三個引數的設定與本函數傳回值, 請參閱 WinAPI 中對 (* MessageBox 的說明 (* (* Delphi 1.0 (* ---------- (* 本函數傳入值為 Object Pascal 式的字串, 如果需 (* 要傳入 PChar 請直接呼叫 Application.MessageBox (* (* Delphi 2.0 (* ---------- (* 以 PChar(LongStr) 即可傳入 Application.MessageBox (* 不一定需要 call 本函數, 只是為了前後版本相容而保留 (* 本函數 (* -------------------------------------------------- *) function MsgBox(const sText, sCaption: string; wFlag: word): integer; {$ifdef Windows} {$define __ShortString} {$endif} {$ifdef Win32} {$ifopt H-} {$define __ShortString} {$endif} {$endif} {$ifdef __ShortString} var szText, szCaption: array[0..254] of char; {$endif} begin {$ifdef __ShortString} StrPCopy(szText, sText); (* 轉換成 Null-Term. 型的字串 *) StrPCopy(szCaption, sCaption); Result := Application.MessageBox(szText, szCaption, wFlag); {$else} Result := Application.MessageBox(PChar(sText), PChar(sCaption), wFlag); {$endif} end; { MsgBox } |
![]() |
如果您是 Delphi 2.0 的使用者, 而且不打算用MessageBox(), 那您可以到 Delphi 2.0 深度歷險 (http://www.aaa.hinet.net/delphi) 取回 CPATCH.ZIP 這個Delphi 2.0 中文修正套件 |
自寸修改 vcl 的方式,
其實也蠻簡單的, 只需改兩行程式而已, 以下是完整的步驟. (使用 1.0 中文應用組件的朋友就不必往下看了,
你們的應該已經是 12 點的字體)
![]() |
1. 將 Delphi\Lib 目錄下的 Dialogs.dcu 備份, 安裝 2.0 中文應用組件的朋友則是 LibTw |
![]() |
2. 將 Delphi\Source\VCL\dialogs.pas複製到一工作目錄, e.g. c:\temp, 2.0 中文應用組件的應該找 Delphi\Source\tw\VCL\dialogs.pas |
![]() |
3. 啟動 Delphi |
![]() |
4. Delphi 1.0: Options | Project
Delphi 2.0: Project | Options, 將 Compiler 那頁的以下開關關掉
|
![]() |
5. 將專案的 unit1.pas Project1.drp 存檔在剛才 Dialogs.pas 的所在目錄, e.g c:\temp |
![]() |
6. 承上, 調出 c:\temp\dialogs.pas, 並作以下修改:
unit Dialogs; <... snipped> function CreateMessageDialog(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons): TForm; <... snipped> begin Result := TMessageForm.CreateNew(Application); with Result do begin BorderStyle := bsDialog; (* Delphi 1.0 與 2.0 程式碼會有一點差異, 但都是將 CreateMessageDialog() 中的 Font.Name 與 Size 換掉為修改重點 *) { VCL Origin: Font.Name := 'Times New Roman'; Font.Size := 9; } Font.Name := 'System'; (* or '細明體', Modify by Wolfgang *) Font.Size := 12; (* Modify by Wolfgang *) Canvas.Font := Font; <... snipped> |
![]() |
7. 執行這個專案, 或者 build all 一次亦可 |
![]() |
8. 在 c:\temp 目錄就會有一個 dialogs.dcu, 將這個檔案複製回 Delphi 的
Lib 目錄(或 LibTw), 然後 --
Delphi 1.0: Options | Rebuild Library Delphi 2.0: Component | Rebuild Library |
首頁 | 學習筆記 | 主題公園 | 軟體下載 | 關於本站 | 討論信群 | 相約下次 |