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

Display Listbox like Delphi's Code-completion Listbox does

Hello,
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...

Quote
>     1) In Delphi I see when I do for example Insightbox.| the window
popups
> were the editor keeps his focus, but also the listbox has focus. Now,
please
> 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);
begin
  inherited CreateParams(Params);
  with Params do
  begin
    Style := Style or WS_THICKFRAME;
    WindowClass.Style := WindowClass.Style or CS_SAVEBITS or CS_DBLCLKS;
    ExStyle := ExStyle or WS_EX_TOOLWINDOW;
  end;
end;

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

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.

Quote
>     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
the
> border/frame edge of the window for resizing purpose.

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

HTH,
--
-Steve
Delphi/BCB R&D
Please no private email unless explicitly invited, thank you.
http://www.geocities.com/delphihelp

Other Threads