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);
  procedure FormKeyPress(Sender: TObject; var Key: Char);
 end;
var
 Form1: TForm1;
implementation
{$R *.dfm}
var
 str: string;
 x1,y1: Integer;
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
var
 x2: Integer;
begin
 HideCaret(Handle);
 Repaint;
 if Key = #8 then
 begin
  if Length(str) > 0 then
  SetLength(str, Length(str) - 1);
 end else str := str + Key;
 Text := str;
 Canvas.TextOut(x1, y1, str);
 x2 := x1 + Canvas.TextWidth(str);
 SetCaretPos(x2, y1);
 ShowCaret(Handle);
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
 Shift: TShiftState; X, Y: Integer);
begin
 str := '';
 DestroyCaret;
 CreateCaret(Handle, 0, 0, Canvas.TextHeight('A'));
 SetCaretPos(X,Y);
 ShowCaret(Handle);
 x1 := X;
 y1 := Y;
end;
end.

窗体文件:

object Form1: TForm1
 Left = 0
 Top = 0
 Caption = 'Form1'
 ClientHeight = 206
 ClientWidth = 339
 Color = clBtnFace
 Font.Charset = DEFAULT_CHARSET
 Font.Color = clWindowText
 Font.Height = -11
 Font.Name = 'Tahoma'
 Font.Style = []
 OldCreateOrder = False
 OnKeyPress = FormKeyPress
 OnMouseDown = FormMouseDown
 PixelsPerInch = 96
 TextHeight = 13
end

时间: 2024-11-17 00:17:20

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

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); proc

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: 输入光标相关的函数[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