Windows API 中的字符串对应这 Delphi 的 PChar(PAnsiChar); 在 API 中使用 Delphi 的字符串还是比较灵活的.
先说赋值:
SetWindowText(Handle, ); ; p: PChar; p := ; SetWindowText(Handle, p); ; str: ; str := ; SetWindowText(Handle, PChar(str)); ; arr: [..] Char; arr := ; SetWindowText(Handle, arr); ;
再说取值:
arr: [..] Char; GetWindowText(Handle, arr, ); ShowMessage(arr); ; p: PChar; GetMem(p, ); GetWindowText(Handle, p, ); ShowMessage(p); FreeMem(p); ; p: HGLOBAL; p := GlobalAlloc(, ); GetWindowText(Handle, PChar(p), ); ShowMessage(PChar(p)); GlobalFree(p); ; str: ; SetLength(str, ); GetWindowText(Handle, PChar(str), ); str := PChar(str); ShowMessage(str); ;
定长字符串不是 #0 结束的, 和 API 不好兼容, 一般不用于 API 中.