TSsringList使用 WM_MouseMove消息 移位异或操作(y shl 16 or X)

{1、显示鼠标在 Panel1 中的坐标}
{2、显示是否同时按住了 Shift、Ctrl、Alt}
procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  List: TStringList;
begin
  List := TStringList.Create;
  if ssShift in Shift then List.Add('Shift');
  if ssCtrl  in Shift then List.Add('Ctrl');
  if ssAlt   in Shift then List.Add('Alt');
  if List.Count > 0 then
    Panel1.Caption := Format('%s: %d, %d', [List.CommaText, X, Y])
  else
    Panel1.Caption := Format('%d, %d', [X, Y]);
  List.Free;
end;
{向 Panel1 发送 WM_MOUSEMOVE 消息}
{第一个消息参数是 0, 表示没有按任何辅助键}
{第二个消息参数是 0, 相当于把鼠标移动到(0,0)坐标}

procedure TForm1.Button2Click(Sender: TObject);
var
  x,y,LParam: Integer;
begin
  x := Panel1.ClientWidth div 2;
  y := Panel1.ClientHeight
div 2;
  LParam := y
shl 16 or x;
  Panel1.Perform(WM_MOUSEMOVE,
0, LParam);
end
;

procedure TForm1.Button3Click(Sender: TObject);
const
  x = 20;
  y = 10;
begin
  Panel1.Perform(WM_MOUSEMOVE, MK_SHIFT+MK_CONTROL, y shl 16 or x);
end;

 

posted @ 2011-09-28 15:48  ftwsnow  阅读(267)  评论(0编辑  收藏  举报