Recent

Author Topic: [Solved] Custom PopupMenu  (Read 5757 times)

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: [Solved] Custom PopupMenu
« Reply #30 on: August 19, 2023, 06:26:00 pm »
What is "activity" then?

I think he means focus.

Edit: It's easy to see and understand. Drop a TBCComboBox into a form, add a few items with the object inspector. Run the application. When the popup shows, the main form looses it focus.

Unlike aydin says, what happens with a virtual keyboard like the one that comes with windows, you open it and the focus remains in the main form.

Set the parent form:
Code: Pascal  [Select][+][-]
  1.     FForm.Parent := GetParentForm(Self, False);

You must also adjust the position of FForm in TBCComboBox.ButtonClick.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

lainz

  • Hero Member
  • *****
  • Posts: 4740
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: [Solved] Custom PopupMenu
« Reply #31 on: August 19, 2023, 07:05:58 pm »
What is "activity" then?

I think he means focus.

Edit: It's easy to see and understand. Drop a TBCComboBox into a form, add a few items with the object inspector. Run the application. When the popup shows, the main form looses it focus.

Unlike aydin says, what happens with a virtual keyboard like the one that comes with windows, you open it and the focus remains in the main form.

Set the parent form:
Code: Pascal  [Select][+][-]
  1.     FForm.Parent := GetParentForm(Self, False);

You must also adjust the position of FForm in TBCComboBox.ButtonClick.

Sorry I'm not at the PC right now. Can you provide a pull request at github, so I can apply it directly?

aydın

  • Jr. Member
  • **
  • Posts: 86
Re: [Solved] Custom PopupMenu
« Reply #32 on: August 19, 2023, 08:04:33 pm »
Set the parent form:
Code: Pascal  [Select][+][-]
  1.     FForm.Parent := GetParentForm(Self, False);

You must also adjust the position of FForm in TBCComboBox.ButtonClick.

This turned out really well, it's working smoothly.

Just one question though, does it have to be inside another form? It would be even better if it could float freely on the screen.
Lazarus 4.99, FPC 3.3.1 on Fedora 42

lainz

  • Hero Member
  • *****
  • Posts: 4740
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: [Solved] Custom PopupMenu
« Reply #33 on: August 19, 2023, 11:13:05 pm »
Just one question though, does it have to be inside another form? It would be even better if it could float freely on the screen.

Oh I see. So it will not work for us...

El Salvador

  • Full Member
  • ***
  • Posts: 141
Re: [Solved] Custom PopupMenu
« Reply #34 on: August 20, 2023, 12:11:34 am »
Some time ago I porting in fpc+lazarus a sample popup form made in delphi: https://github.com/salvadorbs/LazTips.PopupForm Maybe it could help you.

jamie

  • Hero Member
  • *****
  • Posts: 7493
Re: [Solved] Custom PopupMenu
« Reply #35 on: August 20, 2023, 12:50:42 am »
The LCL does a lot of things not proper, but if you complain about it, someone will go out of their way to make it do even more that isn't proper, so it's a no-win situation.

 Have you tried using a TOOL window, those can flood without stealing the focus.


The only true wisdom is knowing you know nothing

aydın

  • Jr. Member
  • **
  • Posts: 86
Re: [Solved] Custom PopupMenu
« Reply #36 on: August 20, 2023, 09:26:51 am »
Some time ago I porting in fpc+lazarus a sample popup form made in delphi: https://github.com/salvadorbs/LazTips.PopupForm Maybe it could help you.
This is working strangely.
Lazarus 4.99, FPC 3.3.1 on Fedora 42

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: [Solved] Custom PopupMenu
« Reply #37 on: August 20, 2023, 12:43:25 pm »
Code: Pascal  [Select][+][-]
  1. procedure TForm2.CreateParams(var Params: TCreateParams);
  2. begin
  3.   inherited CreateParams(Params);
  4.   Params.ExStyle := Params.ExStyle or WS_EX_NOACTIVATE;
  5. end;
but somehow freepascal or lcl is working against such mechanism....

what i try to say, the window must be created with that flag, you can not force it that way AFAIK
I don't know where I went wrong.

No matter what I do, the popup takes the focus.

I found this: https://www.codeproject.com/questions/751002/show-window-without-activating

In addition, to guarantee visibility:
Code: Pascal  [Select][+][-]
  1. Params.ExStyle := Params.ExStyle or WS_EX_NOACTIVATE or WS_EX_TOPMOST;
When you set bounds (note uFlags):
Code: Pascal  [Select][+][-]
  1. SetWindowPos({hMenuWnd}FForm.Handle, 0, FOrigin.X, FOrigin.Y, FForm.Width, FForm.Height, SWP_NOZORDER or SWP_NOACTIVATE);
When you show it:
Code: Pascal  [Select][+][-]
  1. ShowWindow(FForm.Handle, SW_SHOWNOACTIVATE);

i.e. you must put additional "NOACTIVATE" flags/cmds in various places which is quite impossible with LCL unless you wrote your own variant of TCustomForm.

OTOH TDateTimePicker manages to do some kind of "magic" and to look like not grabbing the focus.  :o
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

 

TinyPortal © 2005-2018