首页 > 代码库 > 鼠标拖动虚影效果

鼠标拖动虚影效果

技术分享

 

 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 begin10   case Msg.message of11     WM_LBUTTONDOWN:  //鼠标左键按下显示虚窗体12     begin13       //复制一个主窗体的图片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     begin35       //取出鼠标的位置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     begin44       Form1.Hide;45     end;46   end;47 end;

 

鼠标拖动虚影效果