1 //1.定义消息 2 procedure MYHideMessage(var Msg: tagMSG; var Handled: Boolean); 3 4 //2.执行消息 5 procedure TForm2.MYHideMessage(var Msg: tagMSG; var Handled: Boolean); 6 var 7 pt:TPoint; 8 bit: TBitmap; 9 begin 10 case Msg.message of 11 WM_LBUTTONDOWN: //鼠标左键按下显示虚窗体 12 begin 13 //复制一个主窗体的图片 14 bit := TBitmap.Create; 15 bit.Width := Width; 16 bit.Height := Height; 17 BitBlt(bit.Canvas.Handle, 0, 0, Width, Height, GetWindowDC(Handle), 0, 0, SRCCOPY); 18 //虚窗体加载图片 19 Form1.Image1.Picture.Assign(bit); 20 //我这里为了方便大家看代码没有用TRY,大家写时注意了 21 bit.Free; 22 //设置虚窗体的大小 23 Form1.Height:=Form2.Height; 24 Form1.Width:=Form2.Width; 25 Form1.Image1.Align:=alClient; 26 Form1.BorderStyle:=bsNone; 27 //显示虚窗体 28 Form1.Show; 29 //设置透明度 30 Form1.AlphaBlend:=True; 31 Form1.AlphaBlendValue:=100; 32 end; 33 WM_MOUSEMOVE: //鼠标移动虚窗体根着移动 34 begin 35 //取出鼠标的位置 36 GetCursorPos(pt); 37 Caption:=‘X坐标: ‘+inttostr(pt.X)+‘ Y坐标: ‘+inttostr(pt.Y); 38 //设置虚窗体的位置 39 Form1.Top:=pt.Y; 40 Form1.Left:=pt.X; 41 end; 42 WM_LBUTTONUP: //鼠标左键跳起虚窗体隐藏 43 begin 44 Form1.Hide; 45 end; 46 end; 47 end;
时间: 2024-12-11 13:11:36