[轉貼]更改 ShowMessage 的 OK 鈕的 Caption

有關Delphi 的語法, 程式, 等
回覆文章
頭像
tim
文章: 1380
註冊時間: 2008年 11月 26日, 00:49

[轉貼]更改 ShowMessage 的 OK 鈕的 Caption

文章 tim »

http://delphi.ktop.com.tw/topic.asp?topic_id=30372

在網路上找到的一篇
也可以用相同的方式 runtime 更改 InputBox 的按鈕 Caption
或其它 resourcestring

代碼: 選擇全部

     
    unit Unit1; 
        
    interface 
        
    uses 
      Windows, Messages, SysUtils, Classes, Graphics, Controls, forms, Dialogs, 
      StdCtrls; 
        
    type 
      Tform1 = class(Tform) 
        Button1: TButton; 
        procedure Button1Click(Sender: TObject); 
      private 
        { Private declarations } 
      public 
        { Public declarations } 
      end; 
        
    var 
      form1: Tform1; 
        
    implementation 
        
    uses Consts; // 大部份的 resourcestring 所在 unit 
        
    {$R *.DFM} 
        
    Procedure HookResourceString( rs: PResStringRec; newStr: PChar ); 
    Var oldprotect: DWORD; 
    Begin 
      VirtualProtect(rs, Sizeof(rs^), PAGE_EXECUTE_READWRITE, @oldProtect); 
      rs^.Identifier := Integer(newStr); 
      VirtualProtect(rs, Sizeof(rs^), oldProtect, @oldProtect); 
    End; 
        
    const 
      NewOK: PChar = 'New OK'; // 新的 Caption 值 
        
    procedure Tform1.Button1Click(Sender: TObject); 
    begin 
      ShowMessage('TEST'); 
    end; 
       
    initialization 
      HookResourceString(@SMsgDlgOK, NewOK); // SMsgDlgOK 為 consts unit 中一個變數 
     
    end. 
多多留言, 整理文章, 把經驗累積下來.....
回覆文章