Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 在桌面上书写文本_Delphi_Transparent Control - Fatal编程技术网

Delphi 在桌面上书写文本

Delphi 在桌面上书写文本,delphi,transparent-control,Delphi,Transparent Control,我想在桌面(当前连接的磁盘驱动器)上写一些文本。因此,我将BorderStyle设置为bsNone,TransparentColor设置为true,TransparentColorValue设置为clRed,之后我得到了糟糕的结果: 我怎样才能解决这个问题?我目前已经尝试了6个小时来解决这个问题:/ 也许有另一种方法可以在桌面上(而不是在所有的窗口上)写入文本?谢谢大家的帮助。我刚刚用WinApi重新编写了所有代码。以下是可用的源代码: program test; uses Winapi

我想在桌面(当前连接的磁盘驱动器)上写一些文本。因此,我将
BorderStyle
设置为
bsNone
TransparentColor
设置为
true
TransparentColorValue
设置为
clRed
,之后我得到了糟糕的结果:

我怎样才能解决这个问题?我目前已经尝试了6个小时来解决这个问题:/
也许有另一种方法可以在桌面上(而不是在所有的窗口上)写入文本?

谢谢大家的帮助。我刚刚用WinApi重新编写了所有代码。以下是可用的源代码:

program test;

uses
  Winapi.Windows,
  Winapi.Messages;

var
  s_width: DWORD;
  s_height: DWORD;
  hWind: HWND;
  g_bModalState: boolean = false;
  hStatic: THandle;
  bkGrnd: NativeUInt;

function Proced(hWin, iMsg, wP, lP: integer): integer; stdcall;
var
  hdcStatic: hdc;
begin
  case iMsg of
    WM_WINDOWPOSCHANGING:
      begin
        with PWindowPos(lP)^ do
          hwndInsertAfter := HWND_BOTTOM
      end;
    WM_DESTROY:
      begin
        PostQuitMessage(0);
        Result := 0;
      end;
    WM_CTLCOLORSTATIC:
      begin
        hdcStatic := wP;
        SetBkMode(hdcStatic, TRANSPARENT);
        SetTextColor(hdcStatic, RGB(0, 0, 0));
        Result := bkGrnd;
      end;
    else
      Result := DefWindowProc(hWin, iMsg, wP, lP);
  end;
end;

procedure WinMain();
var
  WinClass: TWndClassEx;
  rc: TRect;
  uMsg: Tmsg;
  hTarget: HWND;
  ClassName: PWideChar;
  textStr: string;
begin
  hTarget := GetDesktopWindow;
  if hTarget < 1 then
    ExitProcess(0);

  GetWindowRect(hTarget, rc);
  s_width := rc.right - rc.left;
  s_height := (rc.bottom - rc.top) div 2;

  ClassName := '#32770';

  bkGrnd := CreateSolidBrush(RGB(255,0,0));

  ZeroMemory(@WinClass, sizeof(WinClass));
  with WinClass do
    begin
      cbSize := SizeOf(WinClass);
      lpszClassName := ClassName;
      lpfnWndProc := @Proced;
      cbClsExtra := 0;
      cbWndExtra := 0;
      hInstance := hInstance;
      lpszMenuName := nil;
      style := CS_HREDRAW or CS_VREDRAW;
      hCursor := LoadCursor(0, IDC_ARROW);
      hbrBackground := bkGrnd;
    end;

  textStr := 'Testing desktop output';

  RegisterClassEx(WinClass);
  hWind := CreateWindowEx(WS_EX_TOOLWINDOW or WS_EX_LAYERED or WS_EX_TRANSPARENT, ClassName, 'testOverlayDELPHI', WS_POPUP or WS_VISIBLE, rc.Left, s_height, s_width, s_height, 0, 0, hInstance, nil);
  SetLayeredWindowAttributes(hWind, RGB(255, 0, 0), 0, ULW_COLORKEY);
  ShowWindow(hWind, SW_SHOW);

  hStatic := CreateWindow('Static', PChar(textStr), WS_VISIBLE or WS_CHILD or SS_RIGHT, s_width - length(textStr) * 9 - 4, s_height - 60, length(textStr) * 9, 20, hWind, 0, hInstance, nil);

  while GetMessage(uMsg, 0, 0, 0) do
    begin
      TranslateMessage(uMsg);
      DispatchMessage(uMsg);
    end;
end;

begin
  WinMain;
end.
程序测试;
使用
Winapi.Windows,
Winapi.Messages;
变量
s_宽度:DWORD;
s_高度:德沃德;
hWind:HWND;
g_bModalState:boolean=false;
hs静电:THandle;
bkGrnd:本地用户;
处理的函数(hWin、iMsg、wP、lP:integer):整数;stdcall;
变量
hdcStatic:hdc;
开始
iMsg案件
WM_WINDOWPOSCHANGING:
开始
与PWindowPos(lP)^do
HwnInsertAfter:=HWND\u底部
结束;
WM_销毁:
开始
PostQuitMessage(0);
结果:=0;
结束;
WM_CTLORSTATIC:
开始
hdcStatic:=wP;
SetBkMode(hdcStatic,透明);
SetTextColor(hdcStatic,RGB(0,0,0));
结果:=bkGrnd;
结束;
其他的
结果:=DefWindowProc(hWin、iMsg、wP、lP);
结束;
结束;
程序WinMain();
变量
WinClass:TWndClassEx;
rc:TRect;
uMsg:Tmsg;
hTarget:HWND;
类名:PWideChar;
textStr:字符串;
开始
hTarget:=GetDesktopWindow;
如果hTarget<1,则
退出过程(0);
GetWindowRect(hTarget,rc);
s_宽度:=rc.right-rc.left;
s_高度:=(钢筋混凝土底部-钢筋混凝土顶部)第2部分;
类名:='#32770';
bkGrnd:=CreateSolidBrush(RGB(255,0,0));
零内存(@WinClass,sizeof(WinClass));
用绞盘做
开始
cbSize:=SizeOf(WinClass);
lpszClassName:=类名称;
lpfnWndProc:=@Proced;
cbClsExtra:=0;
cbWndExtra:=0;
hInstance:=hInstance;
lpszMenuName:=nil;
样式:=CS_HREDRAW或CS_VREDRAW;
hCursor:=加载光标(0,IDC_箭头);
hbrBackground:=bkGrnd;
结束;
textStr:=“测试桌面输出”;
寄存器类(WinClass);
hWind:=CreateWindowEx(WS_-EX_工具窗口或WS_-EX_分层或WS_-EX_透明,类名,'testOverlayDELPHI',WS_弹出或WS_可见,rc.Left,s_高度,s_宽度,s_高度,0,0,hInstance,nil);
SetLayeredWindowAttributes(hWind、RGB(255、0、0)、0、ULW_颜色键);
显示窗口(hWind、SW_SHOW);
hs静态:=CreateWindow('Static',PChar(textStr),WS_可见或WS_子对象或SS_右对象,s_宽度-长度(textStr)*9-4,s_高度-60,长度(textStr)*9,20,hWind,0,hInstance,nil);
而GetMessage(uMsg,0,0,0)执行
开始
翻译信息(uMsg);
调度信息(uMsg);
结束;
结束;
开始
温曼;
结束。

您希望它只显示在桌面上,还是也显示在windows上?还可以尝试使用字体和颜色。这可能会有所帮助:@jerrydoge我希望文本只显示在桌面上。如果没有对原始表单应用透明度,则可能有助于查看其外观。当
TransparentColor
设置为false时,它是什么样子的?正如所怀疑的,您在抗锯齿方面有问题。您看到的剩余颜色是原始黑色文本与原始红色背景混合的部分,以产生灰红色阴影,而不是纯红色,这就是操作系统无法透明绘制这些区域的原因。您必须关闭UI控件上的抗锯齿功能,或使用不支持抗锯齿功能的
Font
。或者使用与壁纸颜色更接近的不同背景
颜色
,这样您就不会太注意到消除混叠了。+1可帮助您自己解决此问题。虽然我还没有检查你的代码,但我可以假设它完全符合你的意图。