Take the 2-minute tour ×

Possible Duplicate:
How to prevent form from being activated when the users clicks on it?

What I exactly mean, is that I want to create a popup window that exactly looks like a Tooltip window. I'm using ShowWindow and SetWindowPos to show and set its position. I already tried SW_SHOWNOACTIVE and it works perfect for the time when the popup appears; but when I click on the popup window, it gets focused, and I don't want this to happen. Also, when this popup is visible no matter it's focused or not, no message is sent to the window placed behind it.

I'm actually writing an Object Inspector component and for long values, it has to show a tooltip when mouse hovers a long value. I want this tooltip to look like a common one. I don't want to use Windows Tooltips not Delphi Tooltip directly. I want to use my own window.

P.S. I thought that this problem is common , and I searched, but I couldn't find an answer that exactly matches my question.

Thanks in advance. Javid

share|improve this question
Have you tried the Enabled property of the form? –  jpfollenius Aug 23 '11 at 11:31
How do you make your tooltip window? Is it a derivative from TControl, or do you make it without the VCL? –  NGLN Aug 23 '11 at 13:36
You want to look your window like the common one, but refuse to use the common wnd... why is that, why do you want to roll your own? –  ain Aug 23 '11 at 18:46
None of those are things I'm looking for. Still one problem is remaining, and that is, I want the click message to be sent to the window, behind the tooltip. –  Javid Aug 23 '11 at 21:19
show 2 more comments

marked as duplicate by Rob Kennedy, Sertac Akyuz, Anders, NGLN, Graviton Aug 24 '11 at 1:34


1 Answer

up vote 1 down vote accepted

Try this:

TMyTooltipWindow = class(TCustomControl)
  procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
  procedure WMMouseActivate(var Message: TWMMouseActivate); message WM_MOUSEACTIVATE;
  procedure CreateParams(var Params: TCreateParams); override;

procedure TMyTooltipWindow.CreateParams(var Params: TCreateParams);
  Params.Style := WS_POPUP or WS_BORDER;
  Params.ExStyle := WS_EX_TOOLWINDOW;
  Params.WindowClass.style := Params.WindowClass.style + CS_SAVEBITS;

procedure TMyTooltipWindow.WMMouseActivate(var Message: TWMMouseActivate);
  Message.Result := MA_NOACTIVATE;

procedure TMyTooltipWindow.WMNCHitTest(var Message: TWMNCHitTest);
  // this will make your window transparent for clicks 
  Message.Result := HTTRANSPARENT;

This will not allow to activate the window with mouse.

Also having a look at THintWindow in Controls.pas might be helpful.

share|improve this answer
add comment
