当前位置 : 主页 > 编程语言 > delphi >

德尔福.反转光标颜色

来源:互联网 收集:自由互联 发布时间:2021-06-23
我想为我的应用程序使用大型倒十字光标. 但我的代码使光标背景倒置.光标仍然是白色的. var IconInfo: TIconInfo; AndMask, Bmp: TBitmap; w, h: Integer;begin w := Screen.Width * 2; h := Screen.Height * 2; // Cre
我想为我的应用程序使用大型倒十字光标.
但我的代码使光标背景倒置.光标仍然是白色的.

var
  IconInfo: TIconInfo;
  AndMask, Bmp: TBitmap;
  w, h: Integer;
begin
  w := Screen.Width * 2;
  h := Screen.Height * 2;

  // Creation And Mask
  AndMask := TBitmap.Create;
  AndMask.Monochrome := True;
  AndMask.Height := h;
  AndMask.Width := w;

  // Draw on And Mask
  AndMask.Canvas.Brush.Color := clWhite;
  AndMask.Canvas.FillRect(AndMask.Canvas.ClipRect);

//  AndMask.Canvas.Pen.Color := clWhite;
  AndMask.Canvas.Pen.Width := 3;
  AndMask.Canvas.MoveTo(w div 2, 0);
  AndMask.Canvas.LineTo(w div 2, h);
  AndMask.Canvas.MoveTo(0, h div 2);
  AndMask.Canvas.LineTo(w, h div 2);

  {Create the "XOr" mask}
  Bmp := TBitmap.Create;
  Bmp.Width := w;
  Bmp.Height := h;
  {Draw on the "XOr" mask}
  Bmp.Canvas.Brush.Color := clWhite;
  Bmp.Canvas.FillRect(Rect(0, 0, w, h));

  IconInfo.fIcon := true;
  IconInfo.xHotspot := w div 2;
  IconInfo.yHotspot := h div 2;
  IconInfo.hbmMask := AndMask.Handle;
  IconInfo.hbmColor := Bmp.Handle;

  Screen.Cursors[1]:= CreateIconIndirect(IconInfo);
  Screen.Cursor:=1;
end;

如何使背景透明和光标倒置?

procedure TForm1.Button1Click(Sender: TObject);

var
  IconInfo: TIconInfo;
  AndMask, Bmp: TBitmap;
  w, h: Integer;
begin
  w := Screen.Width * 2;
  h := Screen.Height * 2;

  // Creation And Mask
  AndMask := TBitmap.Create;
 // AndMask.Monochrome := True;
  AndMask.Height := h;
  AndMask.Width := w;

  // Draw on And Mask
  AndMask.Canvas.Brush.Color := clWhite;
  AndMask.Canvas.FillRect(AndMask.Canvas.ClipRect);

  AndMask.Canvas.Pen.Color := clwhite;
  AndMask.Canvas.Pen.Width := 3;
  AndMask.Canvas.MoveTo(w div 2, 0);
  AndMask.Canvas.LineTo(w div 2, h);
  AndMask.Canvas.MoveTo(0, h div 2);
  AndMask.Canvas.LineTo(w, h div 2);

  {Create the "XOr" mask}
  Bmp := TBitmap.Create;
  Bmp.Width := w;
  Bmp.Height := h;

  {Draw on the "XOr" mask}
  Bmp.Canvas.Brush.Color := clblack;
  Bmp.Canvas.FillRect(Rect(0, 0, w, h));
  Bmp.Canvas.Pen.Color := clwhite;
  Bmp.Canvas.Pen.Width := 3;
  Bmp.Canvas.MoveTo(w div 2, 0);
  Bmp.Canvas.LineTo(w div 2, h);
  Bmp.Canvas.MoveTo(0, h div 2);
  Bmp.Canvas.LineTo(w, h div 2);


  IconInfo.fIcon := true;
  IconInfo.xHotspot := w div 2;
  IconInfo.yHotspot := h div 2;
  IconInfo.hbmMask := AndMask.Handle;
  IconInfo.hbmColor :=  Bmp.Handle;

  Screen.Cursors[1]:= CreateIconIndirect(IconInfo);
  Screen.Cursor:=1;

end;
网友评论