procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
    if Button=mbright then
     begin
    //do you want
      //Edit1.text:='1';
    end;
end;

解决方案 »

  1.   

    hammer_shi(我程序有BUG?是操作系统的问题忙吧?)
       别人说的是窗体外,也就是他的应用程序范围之外,你的方法行不通
       你可以写一个系统Hook,挂钩Mouse事件,当发生右键单击的时候后,先给你的窗体的这个Edit法更新消息,然后在处理系统缺省事件
      

  2.   

    procedure TForm1.Timer1Timer(Sender: TObject);
    var
      CurPoint:TPoint;
      Left,Top:integer;
      Button: TMouseButton;
    begin
      if Button=mbright then
      begin
        GetCursorPos(CurPoint);
        form1.caption:='('+inttostr(CurPoint.x)
          +','+inttostr(CurPoint.y)+')';
      ......
    end;
      

  3.   

    debussy(debussy) 不是说的很明白了吗?用个系统级鼠标钩子函数!
      

  4.   

    去GOOGLE找,网上有很多鼠标钩子的例子
      

  5.   

    问一下,你是想只在某个特定的情况下拦截一次,还是想始终拦截这个鼠标消息。如果只是在某个特定情况下(如选择了某个菜单项或者按了某个按钮后)拦截一次这个鼠标消息的话,可以这样做。在某个特定的情况下,执行下面的代码:Mouse.Capture := Handle;  然后在Form的事件 OnMouseDown 里写代码:
    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer)
    begin
        if Mouse->Capture=Handle then
        begin
            Mouse.Capture = NULL;
            if Button=mbRight then
               Edit1.Text := 'RightMouseDown';
        end;
    end;如果上面的方法不能满足你的需求,就要考虑用钩子函数了。
      

  6.   

    谢谢 我拦截的不止一次 当满足我的条件的时候要反复使用想请教一下  if Mouse->Capture=Handle  在DELPHI里面通不过 我改成      if Mouse.Capture=Handle 也不行 运行不太正常。能不能帮我? 非常感谢?  
      

  7.   

    如果你说的是HOOK的话,我这儿有很多源码,不过大多都很象C++。
      

  8.   

    if Mouse.Capture=Handle 也不行 运行不太正常。
    怎么个不正常,将相关的代码贴出来,帮你分析一下,或将测试程序发到
    [email protected]
      

  9.   

    'Invalid varinant type conversion'
    这就是报的错!procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
        if Mouse.Capture=Handle then
        begin
            Mouse.Capture := NULL;
            if Button=mbRight then
               Edit1.Text := 'RightMouseDown';
        end;
    end;不管我有没有先给Mouse.Capture:=Handle都一样抱的错
      

  10.   

    你的问题,怎么没有 Delphi 的高手帮忙啊。看来你的问题需要用到钩子函
    数(需要写成DLL)。而要写例子,我是用C++Builder的,又不会用Delphi写
    (只能看和简单的Delphi代码编写),所以至今没有再帮你。在没有人帮你
    的情况下,我只能将我的C++Builder写的代码给你啦,你自己将下面的代码翻
    译成Delphi就是了。下面是DLL的源程序代码:HHOOK hHook = NULL;
    HWND hWindow = NULL;
    HINSTANCE hDllIns = NULL;int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
    {
        if (reason==DLL_PROCESS_ATTACH)
            hDllIns = hinst;
        if (reason==DLL_PROCESS_DETACH) {
            if (hHook != NULL)
                UnhookWindowsHookEx(hHook);
        }
        return 1;
    }
    //---------------------------------------------------------------
    LRESULT CALLBACK HookProc(int code, WPARAM wParam, LPARAM lParam)
    {
        AnsiString str;
        EVENTMSG* pMsg;    pMsg = (EVENTMSG*)lParam;
        if (code==HC_ACTION && pMsg->message==
            WM_RBUTTONDOWN && hWindow!=NULL) {
            str = AnsiString("Mouse -- (") +
                LOWORD(pMsg->paramH) + ',' +
                HIWORD(pMsg->paramH) + ')';
            SetWindowText(hWindow, str.c_str());
        }
        return CallNextHookEx(hHook, code, wParam, lParam);
    }__declspec(dllexport) BOOL __stdcall SetHook(HWND hWnd, BOOL load)
    {
        if (load) {
            hWindow = hWnd;
            if (hHook == NULL)
                hHook = SetWindowsHookEx(
                    WH_JOURNALRECORD, (HOOKPROC)
                    HookProc, (HINSTANCE)HInstance, 0);
            return hHook != NULL;
        }
        else {
            if (hHook && UnhookWindowsHookEx(hHook))
                hHook = NULL;
            return hHook == NULL;
        }
    }在你的EXE程序里,调用DLL的函数SetHook,其中的参数 hWnd 是Edit的窗
    口句柄。这样当用户在任何地方按下鼠标右键时,都会在Edit里显示"Mouse
     -- (X,Y)"这样的文字。