English 中文(简体)
如何在使用 mo中点击TPopupMenu的物品时启动行动?
原标题:How to trigger action when use mouse middle click on TPopupMenu s items?
  • 时间:2011-08-06 03:45:39
  •  标签:
  • delphi

我们用 mo点击,在TPopupMenu的菜单中触发行动。 如何在这些菜单项目中引发对湿度点的各种不同行动? 换言之,停用和中点击TPopupmenu的菜单是不同的行动。

最佳回答

I try to combine 2 answers from author NGLN and come out with the following.

界定新等级继承人:

TMyPopupList = class(TPopupList)
protected
  procedure WndProc(var Message: TMessage); override;
end;

procedure TMyPopupList.WndProc(var Message: TMessage);
var H: HWND;
begin
  case Message.Msg of
    WM_MBUTTONDOWN: begin
      H := FindWindow(PChar( #32768 ), nil);
      SendMessage(H, WM_IME_KEYDOWN, VK_RETURN, 0);
    end;
  end;
  inherited WndProc(Message);
end;

initialization
  PopupList.Free;
  PopupList := TMyPopupList.Create;
end.

The Item1Click is an OnClick event handler of TMenuItem that perform based on mouse click:

procedure TForm1.Item1Click(Sender: TObject);
begin
  if (GetKeyState(VK_MBUTTON) and $80 > 0) then
    Caption :=  Middle Click 
  else
    Caption :=  Normal Click ;
end;

Note: #32768 is the default window class name for a pop-up menu, see MSDN documentation.

问题回答

全球<代码>Menus.PopupList变量对所有PopupMenus进行跟踪,处理发给他们的所有批量。 您可以自行推翻这名PopupList:

type
  TMyPopupList = class(TPopupList)
  private
    FMenuItem: TMenuItem;
  protected
    procedure WndProc(var Message: TMessage); override;
  end;

{ TMyPopupList }

procedure TMyPopupList.WndProc(var Message: TMessage);
var
  FindKind: TFindItemKind;
  I: Integer;
  Item: Integer;
  Action: TBasicAction;
  Menu: TMenu;
begin
  case Message.Msg of
    WM_MENUSELECT:
      with TWMMenuSelect(Message) do
      begin
        FindKind := fkCommand;
        if MenuFlag and MF_POPUP <> 0 then
          FindKind := fkHandle;
        for I := 0 to Count - 1 do
        begin
          if FindKind = fkHandle then
          begin
            if Menu <> 0 then
              Item := GetSubMenu(Menu, IDItem)
            else
              Item := -1;
          end
          else
            Item := IDItem;
          FMenuItem := TPopupMenu(Items[I]).FindItem(Item, FindKind);
          if FMenuItem <> nil then
            Break;
        end;
      end;
    WM_MBUTTONUP:
      if FMenuItem <> nil then
      begin
        GetMenuItemSecondAction(FMenuItem, Action);
        Menu := FMenuItem.GetParentMenu;
        if Action <> nil then
        begin
          Menu := FMenuItem.GetParentMenu;
          SendMessage(Menu.WindowHandle, WM_IME_KEYDOWN, VK_ESCAPE, 0);
          Action.Execute;
          Exit;
        end;
      end;
  end;
  inherited WndProc(Message);
end;

initialization
  PopupList.Free;
  PopupList := TMyPopupList.Create;

www.un.org/Depts/DGACM/index_french.htm 例行公文必须写。 Maybe ,这一答案提供了一些帮助,帮助将自己的行动纳入一个组成部分。

注:<代码>下的代码 WM_MENUSlectT 只是从Menus.TPopupList.WndProc复制。 您也可检索<代码>中的MendItem。 http://msdn.microsoft.com/en-us/library/ms647992(v=VS.85).aspx“rel=“nofollow noretinger”>MenuItemFromPoint

但是,正如许多评论已经说过的那样:在实施这一“倡议”功能之前,考虑过两次(或多次)。

You are not notified of such an event. If you were there would be an entry for middle mouse button click in the list of menu notifications.

因此,如果你真想这样做的话,你或许会利用菜单背后的某种黑板。 然而,正如评论中所讨论的,有很好的理由认为,贵组织的提议可能并不合适。

如果中期点击不是一项适当的选择,那么如何使用诸如Ctrl-Click等烟雾中点的某种关键组合来触发另一种行动? TPopupMenu没有与定制点击相关的任何活动。

最好在一次中度湿度 but子上点击。

那么,它更简单。 如果有人要求CTRL,则在你的行动中进行公正的检查:

procedure TForm1.Action1Execute(Sender: TObject);
begin
  if (GetKeyState(VK_CONTROL) and $8000 = 0) then
    // process normal click
  else
    // process ctrl click
end;




相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签