问题是这样,我要在一个控件上右键点击弹出我的菜单,这个控件没有click类的方法,所以采取用函数获取鼠标是否指上它,然后点击弹出菜单,但触发这个点击开始的事件,不知道写在哪里,所以我写在form2.onmousedown里面,但是出错,原因是还要判断是否右键点击,请大家指教一下
function GetFormNameAt ( X, Y : integer ) : string;
  var
  P:TPoint;
  W:TWinControl;
  begin
  P.X := X;
  P.Y := Y;
  W := FindVCLWindow(P); //得到鼠标指针下的VCL可视组件
 if ( nil <> W ) then
  begin
  if w.name = 'china' then //当W的名字为china时(china控件无点击属性但又要右键点他弹出菜单)
  Result := W.Name;//最后返回控件的名称Name
  end
  else
  begin
  Result := '';
  end;
  end;procedure TForm2.Timer1Timer(Sender: TObject);
  var
  winPos:TPoint;
  begin
  GetCursorPos(winpos); //得到当前鼠标指针的在屏幕上的坐标
  //当鼠标指针下的窗体的Name等于china.name时
  if china.name=GetFormNameAt(winpos.X,winpos.Y) then  begin
    PopupMenu1.Popup(winpos.X, winpos.Y);
  end;
end;procedure TForm2.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
    if button = mbright  then
    begin
    self.Timer1.Enabled :=true;
    end;
end;

解决方案 »

  1.   

    如果把form2.onmousedown这个删掉,把timer1.enable设为true;可以用,但是无法写入判断是否右键点击事件
      

  2.   

    用消息捕获.方法如下:  具体实现自己弄把application.onmessage :=appmessage;
    procedure form1.appmessage(var msg :tmsg ; handled :boolean)
    begin
      if (msg.message=wm_Rbuttonclick) and (msg.handle =控件.handle) then
      begin
          PopupMenu1.Popup(winpos.X, winpos.Y);
      end
    end
      

  3.   

    没有现成的,在delphi中右健都为弹出窗口
      

  4.   

    TO andysan() application.onmessage :=appmessage;
    这一行应该写在什么地方啊,应该怎么使用,请讲清楚点吗?