首页  编辑  

运行的时候,改变资源字符串的值

Tags: /超级猛料/String.字符串处理/   Date Created:
change resource strings at run-time?

uses
    Consts;

procedure TForm1.Button1Click(Sender: TObject);
begin
    InputBox('Test', 'Enter something', 'Test');
end;

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';
    NewCancel: PChar = 'New Cancel';

initialization

HookResourceString(@SMsgDlgOK, NewOK);
HookResourceString(@SMsgDlgCancel, NewCancel);

end.

img_30808.bmp (160.4KB)