Board index » delphi » Display Listbox like Delphi's Code-completion Listbox does

Display Listbox like Delphi's Code-completion Listbox does

How can I show a Listbox that appears, like Delphis code-completion Listbox,
to be floating uppon the owning window?
That is:
  - If you click in the listbox the parent window doesn't loose the focus.
  - The listbox is not clipped if it exceeds the window borders.

Thank you.


Re:Display Listbox like Delphi's Code-completion Listbox does

Hi Ma?l,
  I've answered this question before and thought that I would simply post
that reply to help get you going...

>     1) In Delphi I see when I do for example Insightbox.| the window
> were the editor keeps his focus, but also the listbox has focus. Now,
> be so kind and tell me how did this trick, because I have tried everything
> from SetWindowPos upto overwriting the WndProc and catching WM_SETFOCUS.

The code completion window that pops up is not on a form.  The class we use
is just a TCustomListBox descendant.  There are a few things that you need
to do to get this to work correctly.  Even though the class below says it's
a ListView it's really not.  One of the first things you need to do is
parent the control correctly.  In the constructor for this class we set the
parent as follows:

  Parent := Application.MainForm;

Then the following two methods do the bulk of the work getting the window
setup correctly.

procedure TCodeCompleteListBox.CreateParams(var Params: TCreateParams);
  inherited CreateParams(Params);
  with Params do
    Style := Style or WS_THICKFRAME;
    WindowClass.Style := WindowClass.Style or CS_SAVEBITS or CS_DBLCLKS;
    ExStyle := ExStyle or WS_EX_TOOLWINDOW;

procedure TCodeCompleteListBox.CreateWnd;
  inherited CreateWnd;
  Windows.SetParent(Handle, 0);
  CallWindowProc(DefWndProc, Handle, WM_SETFOCUS, 0, 0);

I'll give you a hint (at least on Nt/W2K), one way to dive into an
application is to either run it in a de{*word*81} (like Delphi) or attach to the
application with a de{*word*81} (again Delphi will do) and bring up the window
in question and press F12 which will halt the program leaving you in the
de{*word*81}.  At that point you can use MS Spy++ or Winsight and inspect these
popup windows and see their window styles, parent etc.

>     2) Also in Delphi when you resize the window, the editor keeps his
> focus. In my window,  I lose the focus of the editor after clicking and
> border/frame edge of the window for resizing purpose.

If you get the above working then this will simply fall into place.

Delphi/BCB R&D
Please no private email unless explicitly invited, thank you.

Other Threads