//在画布上绘字 function DispOnDesk(Str,Font:String;x,y,FontSize:Integer;DeskCanvas:TCanvas):Boolean ; begin deskcanvas.Font.Name := Font; deskcanvas.Font.size := FontSize; deskcanvas.TextOut(x,y,Str); beginpath(deskcanvas.Handle); deskcanvas.TextOut(x,y,Str); endpath(deskcanvas.Handle); deskcanvas.Pen.Color :=RGB(0,0,160); StrokePath(deskcanvas.Handle); end;procedure TForm1.Timer3Timer(Sender: TObject); //画布清除 procedure ClearDesk(x,y,x1,y1:Integer); var R: TRect; begin R := Rect(x,y,x1,y1); RedrawWindow(0,@R,0, RDW_INVALIDATE or RDW_ALLCHILDREN); end;//在画布上绘字 function DispOnDesk(Str,Font:String;x,y,FontSize:Integer;DeskCanvas:TCanvas):Boolean ; begin deskcanvas.Font.Name := Font; deskcanvas.Font.size := FontSize; deskcanvas.TextOut(x,y,Str); beginpath(deskcanvas.Handle); deskcanvas.TextOut(x,y,Str); endpath(deskcanvas.Handle); deskcanvas.Pen.Color :=RGB(0,0,160); StrokePath(deskcanvas.Handle); end;procedure TForm1.Timer1Timer(Sender: TObject); var s,StrYB,StrWord,StrComm:String; i,x,y:integer; R: TRect; deskcanvas:TCanvas; begin DeskCanvas:=Tcanvas.create; deskcanvas.Handle:=GetDC(0); x:=screen.Width div 5; y:=Screen.Height div 2 -200; ClearDesk(x,y,x+2000,y+300); //清除画布 Sleep(10) ; //很重要的一句,要不就会显示后就消失 SetBkMode( deskcanvas.Handle, TRANSPARENT ); deskcanvas.Font.style := [fsBold]; deskcanvas.Font.Color :=RGB(255,0,0); x:=x; y:=y+100; DispOnDesk('兄弟们,中秋节快乐...'+strYB+'!','DFPhonetic',x,y,45, deskcanvas) ; x:=x; y:=y+60; DispOnDesk(strcomm,'黑体',x,y,35, deskcanvas) ; ReleaseDC(0,deskcanvas.Handle); end;
可以直接操作当前屏幕的DC Any function that returns a display device context (DC) normally returns a DC for the primary monitor. To obtain the DC for another monitor, use the EnumDisplayMonitors function. Or, you can use the device name from the GetMonitorInfo function to create a DC with CreateDC. However, if the function, such as GetWindowDC or BeginPaint, gets a DC for a window that spans more than one display, the DC will also span the two displays. ------------------------------------------ procedure TForm1.Button1Click(Sender: TObject); var dm : hDC; aa : TCanvas; begin dm := GetWindowDC(0); aa := TCanvas.Create; aa.Handle := dm; aa.TextOut(0,0,'dsfsdfgsdg'); aa.Free; end;
GetWindowDC The GetWindowDC function retrieves the device context (DC) for the entire window, including title bar, menus, and scroll bars. A window device context permits painting anywhere in a window, because the origin of the device context is the upper-left corner of the window instead of the client area. GetWindowDC assigns default attributes to the window device context each time it retrieves the device context. Previous attributes are lost. HDC GetWindowDC( HWND hWnd // handle to window ); Parameters hWnd [in] Handle to the window with a device context that is to be retrieved. If this value is NULL, GetWindowDC retrieves the device context for the entire screen. Windows 98/Me, Windows 2000/XP: If this parameter is NULL, GetWindowDC retrieves the device context for the primary display monitor. To get the device context for other display monitors, use the EnumDisplayMonitors and CreateDC functions.
var
Window: HWND;
WinRect: TRect;
Canvas:TCanvas;
begin
Window := FindWindow('Progman', 'Program Manager');
Windows.GetWindowRect(Window, WinRect);
Canvas:=Tcanvas.Create;
Canvas.handle:=GetDC(0);
with Canvas do
begin
Brush.Style:=bsClear;
Font.Name :='Courier New';
Font.Size:=24;
Font.Style:=[fsBold];
end; Canvas.Font.Color:=clOlive;
Canvas.TextOut(0, 0, '把字输出到屏幕上去');
Canvas.TextOut(0, 100, '第二行字');
ReleaseDC(0,Canvas.Handle);
Canvas.Free;
end;
虽然可以直接往屏幕上写字,但是如果有其它窗口存在,文字写在其它窗体上,窗体移动时文字也跟着移动,画面会错乱。用窗体是可以实现的,用透明的,并且具有鼠标穿透功能的窗体。
// 用下面的控件,放到窗口上,并设置控件的属性就可以实现了。unit TransForm; {DragonPC 2001.2.21 }interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms ;type
TTranForm = class(TComponent)
private
FAlphaValue: integer ;
FTransMouse: Boolean;
FParentFormHandle: HWND ;
procedure SetFAlphaValue(Alpha:integer);
procedure SetTransMouse(value: Boolean);
protected
procedure UpdateDisplay;
public
constructor Create(AOwner: TComponent); override;
published
property AlphaValue: integer read FAlphaValue write SetFAlphaValue ;
property TransMouse: Boolean read FTransMouse write SetTransMouse;
end;procedure Register;function SetLayeredWindowAttributes(Handle: HWND; COLORKEY: COLORREF;
Alpha: BYTE; Flags: DWORD): Boolean; stdcall; external 'USER32.DLL';implementationprocedure Register;
begin
RegisterComponents('Standard', [TTranForm]);
end;procedure TTranForm.SetFAlphaValue(Alpha: integer);
begin
if (Alpha >= 0) and (Alpha < 256) then begin
FAlphaValue := Alpha ;
UpdateDisplay() ;
end;
end;procedure TTranForm.UpdateDisplay;
begin
if (csDesigning in ComponentState) then Exit ;
SetLayeredWindowAttributes(FParentFormHandle, 0, FAlphaValue, 2);
end;constructor TTranForm.Create(AOwner: TComponent);
begin
inherited;
if (csDesigning in ComponentState) then
Exit;
FAlphaValue := 255 ;
FParentFormHandle := TForm(AOwner).Handle ;
SetWindowLong(FParentFormHandle, GWL_EXSTYLE,
GetWindowLong(FParentFormHandle, GWL_EXSTYLE) or $80000);
end;procedure TTranForm.SetTransMouse(value: Boolean);
begin
if FTransMouse <> value then
begin
FTransMouse := value;
if value then
SetWindowLong(FParentFormHandle, GWL_EXSTYLE,
GetWindowLong(FParentFormHandle, GWL_EXSTYLE) or WS_EX_TRANSPARENT)
else
SetWindowLong(FParentFormHandle, GWL_EXSTYLE,
GetWindowLong(FParentFormHandle, GWL_EXSTYLE) and not WS_EX_TRANSPARENT);
end;
end;end.
To:ahjoe(强哥)
上面的代码是2000 XP支持的,可以调节透明度。但是在98下无效啊。这个我知道。
另外弹出窗口会使其他窗口失去焦点。比如你玩全屏幕游戏的时候。To:hthunter(核桃-我的心在下雨,雨中我和她携手漫步)
这个方法我用过,觉得不是很完美,所以来问问。我是想象显示器设置那样!如何做?有没有显示器操作的接口什么的?感谢每一个回复帖子的人。
TScreen也封装了同样方法,得到了监视器窗口句柄以后,看看能不能在那上面TextOut
应该是硬件方面的问题了
看看能不能从video card着手
function DispOnDesk(Str,Font:String;x,y,FontSize:Integer;DeskCanvas:TCanvas):Boolean ;
begin
deskcanvas.Font.Name := Font;
deskcanvas.Font.size := FontSize;
deskcanvas.TextOut(x,y,Str);
beginpath(deskcanvas.Handle);
deskcanvas.TextOut(x,y,Str);
endpath(deskcanvas.Handle);
deskcanvas.Pen.Color :=RGB(0,0,160);
StrokePath(deskcanvas.Handle);
end;procedure TForm1.Timer3Timer(Sender: TObject);
//画布清除
procedure ClearDesk(x,y,x1,y1:Integer);
var R: TRect;
begin
R := Rect(x,y,x1,y1);
RedrawWindow(0,@R,0, RDW_INVALIDATE or RDW_ALLCHILDREN);
end;//在画布上绘字
function DispOnDesk(Str,Font:String;x,y,FontSize:Integer;DeskCanvas:TCanvas):Boolean ;
begin
deskcanvas.Font.Name := Font;
deskcanvas.Font.size := FontSize;
deskcanvas.TextOut(x,y,Str);
beginpath(deskcanvas.Handle);
deskcanvas.TextOut(x,y,Str);
endpath(deskcanvas.Handle);
deskcanvas.Pen.Color :=RGB(0,0,160);
StrokePath(deskcanvas.Handle);
end;procedure TForm1.Timer1Timer(Sender: TObject);
var s,StrYB,StrWord,StrComm:String;
i,x,y:integer;
R: TRect;
deskcanvas:TCanvas;
begin
DeskCanvas:=Tcanvas.create;
deskcanvas.Handle:=GetDC(0);
x:=screen.Width div 5;
y:=Screen.Height div 2 -200;
ClearDesk(x,y,x+2000,y+300); //清除画布
Sleep(10) ; //很重要的一句,要不就会显示后就消失
SetBkMode( deskcanvas.Handle, TRANSPARENT );
deskcanvas.Font.style := [fsBold];
deskcanvas.Font.Color :=RGB(255,0,0);
x:=x; y:=y+100;
DispOnDesk('兄弟们,中秋节快乐...'+strYB+'!','DFPhonetic',x,y,45, deskcanvas) ;
x:=x; y:=y+60;
DispOnDesk(strcomm,'黑体',x,y,35, deskcanvas) ;
ReleaseDC(0,deskcanvas.Handle);
end;
Any function that returns a display device context (DC) normally returns a DC for the primary monitor. To obtain the DC for another monitor, use the EnumDisplayMonitors function. Or, you can use the device name from the GetMonitorInfo function to create a DC with CreateDC. However, if the function, such as GetWindowDC or BeginPaint, gets a DC for a window that spans more than one display, the DC will also span the two displays. ------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
var
dm : hDC;
aa : TCanvas;
begin
dm := GetWindowDC(0);
aa := TCanvas.Create;
aa.Handle := dm;
aa.TextOut(0,0,'dsfsdfgsdg');
aa.Free;
end;
The GetWindowDC function retrieves the device context (DC) for the entire window, including title bar, menus, and scroll bars. A window device context permits painting anywhere in a window, because the origin of the device context is the upper-left corner of the window instead of the client area. GetWindowDC assigns default attributes to the window device context each time it retrieves the device context. Previous attributes are lost. HDC GetWindowDC(
HWND hWnd // handle to window
);
Parameters
hWnd
[in] Handle to the window with a device context that is to be retrieved. If this value is NULL, GetWindowDC retrieves the device context for the entire screen.
Windows 98/Me, Windows 2000/XP: If this parameter is NULL, GetWindowDC retrieves the device context for the primary display monitor. To get the device context for other display monitors, use the EnumDisplayMonitors and CreateDC functions.