var canvas:Tcanvas;canvas:=Tcanvas.Create; canvas.Handle:=getdc(edit1.Handle); 在edit1的onChange中算x canvas.Draw(x,y,graphic);
这是Delphi的翻译,只是一段一段的翻,没有查过是不是对的,不过,Delphi是很强大的东东,而BCB和Delphi的底层是一个东东。 在Form中加入成员OldWndProc:TWndMothod; 声明个指针PImage:^TImage; 在Form中加入函数MyWndProc(var Message:TMessage);stdcall; 在Form.Create中写入 OldWndProc = Edit1.WindowProc; Edit1.WindowProc = MyWndProc; PImage = nil; 2.在MyWndProc(var Message:TMessage)函数的实现中加入如下代码 TForm.MyWndProc(var Message:TMessage);stdcall; var cp:pointer; begin OldWndProc(Message); case Message.Msg of WM_SETFOCUS: begin if PImage<>nil then exit; PImage:=new(TImage(Edit1)); PImage.Parent:= Edit1; PImage.Picture.LoadFromFile("yourFileName.bmp"); if (!GetCaretPos(@cp)) exit; PImage.Top := cp.y; PImage.Left := cp.x; end; WM_KILLFOCUS: begin decllocate(PImage); PImage := nil; end WM_CHAR: begin if (!GetCaretPos(&cp)) then exit; PImage.Top := cp.y; PImage.Left := cp.x; end end end
var canvas:Tcanvas; icon:Ticon; sh:TSHFileInfoA; begin try icon:=Ticon.create; canvas:=Tcanvas.Create; canvas.Handle:=getdc(edit1.handle); shgetfileinfo('d:\abc.exe',0,sh,sizeof(sh),SHGFI_ATTRIBUTES or SHGFI_ICON or SHGFI_SMALLICON); icon.Handle:=sh.hIcon; canvas.Draw(0,0,icon); canvas.textout(icon.width div 2,0,edit1.text); Invalidate; finally icon.free; canvas.free; end; end; 试试吧
怎样重绘?
在Form中加入成员TWndMothod OldWndProc;
在Form中加入成员TImage* Image;
在Form中加入函数void __fastcall MyWndProc(TMessage& Message);
在Form的构造函数中写入
OldWndProc = Edit1->WindowProc;
Edit1->WindowProc = MyWndProc;
Image = NULL;
2.在void __fastcall MyWndProc(TMessage& Message)函数的实现中加入如下代码
好
void __fastcall TForm1::MyWndProc(TMessage& Message)
{
OldWndProc(Message);
switch(Message.Msg)
{
case WM_SETFOCUS:
{
if (Image != NULL)
return; Image = new TImage(Edit1);
Image->Parent = Edit1;
Image->Picture->LoadFromFile("yourFileName.bmp"); POINT cp;
if(!GetCaretPos(&cp))
return;
Image->Top = cp.y;
Image->Left = cp.x; return;
} case WM_KILLFOCUS:
{
delete Image;
Image = NULL;
return;
} case WM_CHAR:
{
POINT cp;
if(!GetCaretPos(&cp))
return;
Image->Top = cp.y;
Image->Left = cp.x; return;
}
}
}
在Delphi中如何改?
canvas:Tcanvas;canvas:=Tcanvas.Create;
canvas.Handle:=getdc(edit1.Handle);
在edit1的onChange中算x
canvas.Draw(x,y,graphic);
声明个指针PImage:^TImage;
在Form中加入函数MyWndProc(var Message:TMessage);stdcall;
在Form.Create中写入
OldWndProc = Edit1.WindowProc;
Edit1.WindowProc = MyWndProc;
PImage = nil;
2.在MyWndProc(var Message:TMessage)函数的实现中加入如下代码 TForm.MyWndProc(var Message:TMessage);stdcall;
var
cp:pointer;
begin
OldWndProc(Message);
case Message.Msg of
WM_SETFOCUS:
begin
if PImage<>nil then
exit; PImage:=new(TImage(Edit1));
PImage.Parent:= Edit1;
PImage.Picture.LoadFromFile("yourFileName.bmp");
if (!GetCaretPos(@cp))
exit;
PImage.Top := cp.y;
PImage.Left := cp.x;
end;
WM_KILLFOCUS:
begin
decllocate(PImage);
PImage := nil;
end
WM_CHAR:
begin
if (!GetCaretPos(&cp)) then
exit;
PImage.Top := cp.y;
PImage.Left := cp.x; end
end
end
icon:Ticon;
sh:TSHFileInfoA;
begin
try
icon:=Ticon.create;
canvas:=Tcanvas.Create;
canvas.Handle:=getdc(edit1.handle);
shgetfileinfo('d:\abc.exe',0,sh,sizeof(sh),SHGFI_ATTRIBUTES or SHGFI_ICON or SHGFI_SMALLICON);
icon.Handle:=sh.hIcon;
canvas.Draw(0,0,icon);
canvas.textout(icon.width div 2,0,edit1.text);
Invalidate;
finally
icon.free;
canvas.free;
end;
end;
试试吧