UpdateLayeredWindow with normal canvas/textout

人盡茶涼 提交于 2019-12-07 08:17:14

问题


Is there a way to draw on form with canvas and then use the updatelayeredwindow so not the form will be visible but the text, like a transculent form showing only text? if not, then is there a way to make some sort of transculent form with only the canvas (opengl/directx) maybe? i would like to draw with commands on the top of all windows.


回答1:


You can set the TransparentColor property of the form to 'True', then set the form color to the same color of TransparentColorValue, and all of the form's client area will be transparent. If the Delphi version you use does not have the 'TransparentColor[Value]' properties you can achieve the same with API calls:

  Color := clBlack;
  SetWindowLong(Handle, GWL_EXSTYLE,
      GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED );
  SetLayeredWindowAttributes(Handle, 0, 255, LWA_COLORKEY);

will make the forms client area transparent. You can paint on the canvas as you normally would:

procedure TForm1.FormPaint(Sender: TObject);
begin
  Canvas.Font.Color := clWhite;
  Canvas.TextOut(0, 0, 'Text');
end;

Of course you can also put a label on the form having a font color anything different then the transparent color.



来源:https://stackoverflow.com/questions/8555484/updatelayeredwindow-with-normal-canvas-textout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!