鼠标拖动的问题解决了
现在不可以右键删除了?还是找不到焦点或者句柄
我把我的代码贴出来,大家参考以下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,QExtCtrls, StdCtrls, ExtCtrls, Menus, DB, ADODB;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
PopupMenu1: TPopupMenu;
Edit1: TEdit;
Button2: TButton;
N1: TMenuItem;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
showhint1: TMenuItem;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure showhint1Click(Sender: TObject);
private
{ Private declarations }
public
procedure mm(Sender: TObject
Shift: TShiftState
X,Y: Integer);
//procedure bcd(Sender: TObject
Button: TMouseButton;Shift: TShiftState
X, Y: Integer);
procedure md(Sender: TObject
Button: TMouseButton;Shift: TShiftState
X, Y: Integer);
{ Public declarations }
end;
var
Form1: TForm1;
i,k,j:integer;
p : array[1..99] of Tpanel;
imgku:Array[1..99] of TImage;
dwstyle:dword;
h:thandle;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
inc(i);
{动态创建panel}
p:=tpanel.Create(self);
p.Parent:=panel1;
p.Width:=60;
p.Height:=60;
{动态创建imgku}
imgku:=timage.Create(self);
imgku.parent:=p;
imgku.Align:=alclient;
imgku.Picture.LoadFromFile('c:/zhuye.bmp');
imgku.Stretch:=true;//拉伸
imgku.Visible:=true;
imgku.OnMouseMove:=mm;
imgku.OnMouseDown:=md;
imgku.PopupMenu:=popupmenu1;
imgku.ShowHint:=true;
k:=i;
//k可以变化,固定i为了下一个创建图片
end;
procedure Tform1.mm (Sender: TObject
Shift: TShiftState
X,Y: Integer);
begin
//??????????????????//
//这个地方k值不能变?//
//??????????????????//
p[k].Cursor:=crhandpoint;
end;
procedure tform1.md(Sender: TObject
Button: TMouseButton;Shift: TShiftState
X, Y: Integer);
begin
if p[k].Cursor = crhandpoint then
begin
releasecapture();
TControl(sender).Parent.Perform(WM_SYSCOMMAND, $F012, 0);
//sendmessage(p[k].Handle,WM_NCLBUTTONDOWN , HTCAPTION, 0);
//showmessage(inttostr(j));
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
i:=0
//初始化数组
if assigned(p[k]) then
begin
//修改此单字符串窗口组件性质,可自由缩放大小
dwstyle := getwindowlong(p[j].Handle,GWL_STYLE);
//修正此单字符串窗口组件在Form1上的实际尺寸与范围
//以便USER直接调整单字符串窗口组件边沿
setwindowlong(p[k].Handle,GWL_STYLE,dwstyle or WS_SIZEBOX);
movewindow(p[k].Handle,p[k].Left,p[k].Top,p[k].Width,p[k].Height+1,true);
//如果p[j].height+1 可以拖动
//如果p[j].height 不可拖动
end;
adoquery1.SQL.Add('select * from ku');
adoquery1.Active:=true;
adoquery1.first;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
//k不是动态的传递imgku[k]中的数值
k:=strtoint(edit1.text);
end;
procedure TForm1.N1Click(Sender: TObject);
begin
//解决动态查找句柄此删除问题可解决
imgku[k].ShowHint:=false;
imgku[k].Free;
p[k].Free;
end;
procedure TForm1.showhint1Click(Sender: TObject);
var
name:string;
info:string;
begin
//通过一个窗体传递信息
//当前自定义的
//还是上面的句柄解决不了,这个地方也有问题
name:=adoquery1.Fields[0].AsString;
info:=adoquery1.Fields[1].AsString;
imgku[k].Hint:='name:'+name+'. '+'库存种类:'+info;
adoquery1.Next;
end;
end.