吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 522|回复: 14
收起左侧

[求助] 如何把文字重绘在屏幕上(而不是Form上)?

[复制链接]
冥界3大法王 发表于 2024-1-18 12:48

[Delphi] 纯文本查看 复制代码
unit Unit7;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  Vcl.StdCtrls;

type
  TForm7 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form7: TForm7;

implementation

{$R *.dfm}

procedure TForm7.Button1Click(Sender: TObject);
const
  arr: array[0..3] of WideString = ('白日依山尽', '黄河入海流', '欲穷千里目', '更上一层楼');
  a = 20; {横向间隔}
  b = 20; {纵向间隔}
var
  s: string;
  x, y: Integer;
  i, j: Integer;
begin
  x := 20;
  y := 20;

  for i := 0 to Length(arr) - 1 do
  begin
    for j := 1 to Length(arr[i]) do
    begin
      s := arr[i][j];
      Canvas.TextOut(x, y, s);
      x := x + Canvas.TextWidth(s) + a;
    end;
    x := 20;
    y := y + Canvas.TextHeight(s) + b;
  end;
end;

end.

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

sai609 发表于 2024-1-18 13:15
print函数
头号玩家 发表于 2024-1-18 13:32
龙不死 发表于 2024-1-18 13:41
在你的代码中,文字是在TForm7的Canvas上绘制的,因此它将在TForm7的客户区域上绘制文字。如果你想在屏幕上的其他地方绘制文字,而不是在窗体上,你可以使用Screen对象的Canvas属性来获取整个屏幕的Canvas。下面是修改后的代码:
[Delphi] 纯文本查看 复制代码
unit Unit7;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  Vcl.StdCtrls;

type
  TForm7 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form7: TForm7;

implementation

{$R *.dfm}

procedure TForm7.Button1Click(Sender: TObject);
const
  arr: array[0..3] of WideString = ('白日依山尽', '黄河入海流', '欲穷千里目', '更上一层楼');
  a = 20; {横向间隔}
  b = 20; {纵向间隔}
var
  s: string;
  x, y: Integer;
  i, j: Integer;
begin
  x := 20;
  y := 20;

  for i := 0 to Length(arr) - 1 do
  begin
    for j := 1 to Length(arr[i]) do
    begin
      s := arr[i][j];
      Screen.Canvas.TextOut(x, y, s);  // 使用Screen.Canvas来绘制在整个屏幕上
      x := x + Screen.Canvas.TextWidth(s) + a;
    end;
    x := 20;
    y := y + Screen.Canvas.TextHeight(s) + b;
  end;
end;

end.
 楼主| 冥界3大法王 发表于 2024-1-18 14:40
龙不死 发表于 2024-1-18 13:41
在你的代码中,文字是在TForm7的Canvas上绘制的,因此它将在TForm7的客户区域上绘制文字。如果你想在屏幕上 ...

[dcc32 Error] Unit7.pas(89): E2003 Undeclared identifier: 'Canvas'

[dcc32 Error] Unit7.pas(89): E2010 Incompatible types: 'Integer' and 'string'

全是错误 。。。
 楼主| 冥界3大法王 发表于 2024-1-18 14:47
本帖最后由 冥界3大法王 于 2024-1-18 15:24 编辑

自己看,左上角的未注册字样就是用这个函数

image.png
我也要模拟实现一个!
DEATHTOUCH 发表于 2024-1-19 00:36
啥意思,难道是绘制到Windows顶层,还是软件的顶层?
flyer_2001 发表于 2024-1-19 00:42
老版本的话可能是查找桌面句柄,然后调用TextOut输出,
新版不知道有没有提供直接操作桌面的函数,没有delphi环境,没办法运行。
 楼主| 冥界3大法王 发表于 2024-1-19 09:02
flyer_2001 发表于 2024-1-19 00:42
老版本的话可能是查找桌面句柄,然后调用TextOut输出,
新版不知道有没有提供直接操作桌面的函数,没有del ...

我找本Delphi图形绘制输出的pdf
看几个入门的实例就懂了。
flyer_2001 发表于 2024-1-19 13:44
冥界3大法王 发表于 2024-1-19 09:02
我找本Delphi图形绘制输出的pdf
看几个入门的实例就懂了。


涉及到置前的问题,一般采用透明窗体,在透明窗体上输出的方式
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-12 09:51

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表