Jump to content
at3s

Is it possible to multiselect in Popup using Ctrl+<Mouse click> ?

Recommended Posts

I'd like to realize a multiselection in Popup Ctrl+<Mouse click>.

I've owerwrite a TPopupList.WndProc in recreated PopupList object and defined mouse and keyboard hooks on popup.

So I able to mark an item as selected (checked) in popup by pressing space button, but I'm not able to make it working with the Ctrl+<Mouse click> - popup always closes.

 

Keyboard hook:

function PopupMenuKeyboardHookProc(Code: Integer; wParam : WPARAM; lParam : LPARAM): Longint; stdcall;
begin
  try
    if (Code = HC_ACTION) and (wParam = WM_KEYUP) then
    begin
      if PKBDLLHOOKSTRUCT(lParam)^.vkCode = VK_SPACE then
      begin
        if Assigned(PopupList) then
        begin
          PostMessage(PopupList.Window, WM_POPUP_SPACE_KEY_MINE, wParam, lParam);
          wParam := WM_NULL;
          lParam := 0;
        end;
      end;
    end;
  finally
    Result := 0; 
  end;
end;

I tries to process WM_LBUTTONDOWN and WM_LBUTTONUP messages, but without success, popup anyway receives WM_MENUSELECT message with the (Msg.MenuFlag = $FFFF)and(Msg.Menu = 0)), so it closes.
end;

How to catch it?

Share this post


Link to post

No, not using a standard TPopupMenu. The menu loop is being handled by Windows (via the TrackPopupMenu API function) and you do not have any control of how it behaves - and that's how it should be; Altering the behavior of something like a menu just leads to poor usability. The fact that you've had to resort to keyboard & mouse hooks should be a hint that they don't want you messing with it.

 

I suggest you display a non-modal form instead. You can easily make that behave like a popup menu, with your custom behavior, without raping the system.

  • Thanks 1

Share this post


Link to post
9 minutes ago, Anders Melander said:

No, not using a standard TPopupMenu. The menu loop is being handled by Windows (via the TrackPopupMenu API function) and you do not have any control of how it behaves - and that's how it should be; Altering the behavior of something like a menu just leads to poor usability. The fact that you've had to resort to keyboard & mouse hooks should be a hint that they don't want you messing with it.

 

I suggest you display a non-modal form instead. You can easily make that behave like a popup menu, with your custom behavior, without raping the system.

Thank you, it sounds reasonable.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×