gpt4 book ai didi

delphi - 在桌面上书写文字

转载 作者:行者123 更新时间:2023-12-03 14:59:55 25 4
gpt4 key购买 nike

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

enter image description here

我该如何解决这个问题?我目前已经尝试修复这个问题 6 个小时了:/也许还有另一种在桌面上(不是在所有 Windows 上)写入文本的方法?

最佳答案

感谢大家的帮助。我刚刚用 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.

关于delphi - 在桌面上书写文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24026628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com