unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
Found: boolean;
i,SelSt,j: Integer;
TmpStr: string;
begin
with (Sender as TEdit) do
begin
j :=0;
SelSt :=SelStart;
if (Key = Chr(vk_Back)) and (SelLength <> 0) then
TmpStr := Copy(Text,1,SelStart)+Copy(Text,SelLength+SelStart+1,255)
else if Key = Chr(vk_Back) then {SelLength = 0}
TmpStr := Copy(Text,1,SelStart-1)+Copy(Text,SelStart+1,255)
else if Key in [‘0‘..‘9‘] then
begin
TmpStr := Copy(Text,1,SelStart)+Key+Copy(Text,SelLength+SelStart+1,255);
j :=1;
end
else {Key in [‘A‘..‘Z‘, etc]}
TmpStr := Copy(Text,1,SelStart)+Copy(Text,SelStart+1,255);
if (Key = Chr(vk_Back)) and (SelSt > 0) then
Dec(SelSt)
else if Key <> Chr(vk_Back) then
Inc(SelSt);
Key := #0; { indicate that key was handled }
if SelSt = 0 then
begin
Text:= ‘‘;
Exit;
end
else
begin
Text :=TmpStr;
SelStart :=SelSt+j;
end;
end;
end;
end.
{因为ComboBox是个组合控件,所有只替换CombobOx的消息处理过程是没办法截获它的子控件Edit的消息的,针对TComboBox,你可以这样改:}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
oldwndproc:TWndMethod;//保存原来的
procedure EditWndProc(var Message : TMessage);
end;
var
Form1: TForm1;
EditHandle: THandle;
EditPointer:Pointer;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.EditWndProc(var Message: TMessage);
begin
case Message.Msg of
WM_COPY : exit;//做你想做的
WM_PASTE : exit;
end;
Message.Result:=CallWindowProc(EditPointer, EditHandle, Message.Msg, Message.WParam, Message.LParam);
//oldwndproc(Message);
end;
procedure TForm1.FormCreate(Sender: TObject);
Var P:Pointer;
begin
EditHandle:=GetWindow(Combobox1.Handle,GW_CHILD);
if EditHandle<>0 then
begin
if ComboBox1.Style=csSimple then EditHandle:=GetWindow(EditHandle, GW_HWNDNEXT);
EditPointer := Pointer(GetWindowLong(EditHandle, GWL_WNDPROC));
//
P := Classes.MakeObjectInstance(EditWndProc);
SetWindowLong(EditHandle, GWL_WNDPROC, Longint(P));
end;
//oldwndproc:=combobox1.WindowProc;
//Combobox1.WindowProc := ImageWndProc;
end;
end.
*****************************************
用delphi修改 文件属性
1. 在interface下的uses中引用filectrl单元
2. 首先取文件属性
var
attr : integer;
filename : string;
begin
filename := ‘myfile‘;
attr := FileGetAttr(filename);
end;
3. 设置文件属性(如设置归档属性 -> faArchive )
attr := attr or faArchive;
//如要去掉某一属性,则如下句
attr := attr and (not faArchive);
//保留其它属性
if FileSetAttr(filename, attr)=0 then
//成功代码
else
//失败代码
4. 附文件属性常量
Constant Value Description
faReadOnly $00000001 Read-only files 只读文件
faHidden $00000002 Hidden files 隐藏文件
faSysFile $00000004 System files 系统文件
faVolumeID $00000008 Volume ID files 卷标文件
faDirectory $00000010 Directory files 目录
faArchive $00000020 Archive files 归档文件
faAnyFile $0000003F Any file 任意文件