Delphi调用WinAPI: 输入光标相关的函数[3]

本例测试修改光标的形色, 效果图:

代码文件:unit Unit1;
interface
uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls, ExtCtrls;
type
 TForm1 = class(TForm)
  RadioGroup1: TRadioGroup;
  procedure FormCreate(Sender: TObject);
  procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
   Shift: TShiftState; X, Y: Integer);
  procedure RadioGroup1Click(Sender: TObject);
  procedure FormDestroy(Sender: TObject);
 end;
var
 Form1: TForm1;
implementation
{$R *.dfm}
var
 bit: TBitmap;
procedure TForm1.FormCreate(Sender: TObject);
const
 c = '★';
begin
 RadioGroup1.Caption := '光标形色';
 RadioGroup1.Items.CommaText := '黑色,灰度,自定义';
 RadioGroup1.ItemIndex := 0;
 bit := TBitmap.Create;
 bit.Canvas.Font.Size := 16;
 bit.Width := bit.Canvas.TextWidth(c);
 bit.Height := bit.Canvas.TextHeight(c);
 bit.Canvas.TextOut(0, 0, c);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
 SetCaretBlinkTime(530);
 bit.Free;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
 Shift: TShiftState; X, Y: Integer);
var
 h: HBITMAP;
begin
 DestroyCaret;
 h := 0;
 case RadioGroup1.ItemIndex of
  1: h := 1;
  2: h := bit.Handle;
 end;
 CreateCaret(Handle, h, 4, 32);
 SetCaretPos(X,Y);
 ShowCaret(Handle);
end;
procedure TForm1.RadioGroup1Click(Sender: TObject);
var
 h: HBITMAP;
 pt: TPoint;
begin
 GetCaretPos(pt);
 DestroyCaret;
 h := 0;
 case RadioGroup1.ItemIndex of
  1: h := 1;
  2: h := bit.Handle;
 end;
 CreateCaret(Handle, h, 4, 32);
 SetCaretPos(pt.X, pt.Y);
 ShowCaret(Handle);
end;
end.

时间: 2024-12-02 06:21:21

Delphi调用WinAPI: 输入光标相关的函数[3]的相关文章

Delphi调用WinAPI: 输入光标相关的函数[2]

本例测试修改光标的设置闪烁速度, 注意这会影响到其他程序, 退出时应恢复到系统 默认的 530 毫秒. 本例效果图: 代码文件:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) RadioGroup1: TRadioGroup; pr

Delphi调用WinAPI: 输入光标相关的函数[4]

本例效果图: 代码文件:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); p

Delphi调用WinAPI: 输入光标相关的函数[1]

CreateCaret {建立} DestroyCaret {释放} ShowCaret {显示} HideCaret {隐藏} SetCaretPos {设置位置} GetCaretPos {获取位置} SetCaretBlinkTime {设置间隔时间} GetCaretBlinkTime {获取间隔时间} 简单测试, 效果图: 代码文件:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Gr

Delphi调用WinAPI 字符及字符串函数(14): CharToOem、OemToChar

CharToOemBuff.OemToCharBuff 与 CharToOem.OemToChar 的区别只是前者可以指 定要转换的字符数.unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButt

Delphi调用WinAPI 字符及字符串函数(13)

lstrcmp.lstrcmpi - 对比串 lstrcmp 区分大小写; lstrcmpi 不区分大小写. 返回值: -1.0.1, 其中 0 表示相 同. unit Unit1;interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Butto

Delphi调用WinAPI 字符及字符串函数(12): lstrlen

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Se

Delphi调用WinAPI 字符及字符串函数(11)

lstrcpyn - 复制字符串, 同时指定要复制的长度 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); end; var Form1

Delphi调用WinAPI 字符及字符串函数(10)

lstrcpy - 复制字符串 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; procedure Button1Click(Sender: T

Delphi调用WinAPI 字符及字符串函数(9)

lstrcat - 合并字符串 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; procedure Butt