4

I'm working on a personal project and I have been running into lots of issues lately resulting in many questions, but hey, thats what SO is for right? ;)

Anyhow I tried making a transparent TPanel which I achieved by making a custom component. The app im making is about world of warcraft and I made a talent calculator like on the official website but in a windows application. Talents are spells/skills and each talent has information which is displayed in a tooltip.

So I have a tooltip with info,

I have a grid with talents and when I hover on a talent I want to see the info. Besides that, I want the info to be shown near the position of the cursor.

Almost works. The positioning works, it shows the correct info BUT! here is the problem. Take a look at this image: Talent screen

The black semi-transparent panel is my tooltip. You see the talents (that little 4x6 grid) those are located in a dark grey panel called pnlTalents The parent of that panel is the lighter grey panel that covers the entire form called Panel1. The tooltip called TooltipTalent also has the parent Panel1. I have tried sending pnlTalents to the back and bring TooltipTalent to the front but this made no difference at all. I even tried TooltipTalent.BringToFront; the moment the position is changed. Notice how the tooltip has no problem being on top of that darker grey panel at the top of the screen with the speedbuttons. I compared both panels (the one at the top and the one with the talents) and found no difference in the properties. I am seriously running out of ideas here. I have no clue what is causing it and how I can solve this problem.

As last resort I tried dropping another transparent panel that covers the entire form to see if that would help but the problem still persisted.

I could also post the code of my custom component but that would be a lot. If you want to see the code let me know and i'll find a way to show it :)

Can anyone help me on this? Kind regards

Teun Pronk
  • 1,367
  • 12
  • 24
  • 1
    `TToolWindow` and `THintWindow` inherit from `TWinControl` and should show just fine. Is your tooltip a custom control that descents from `TControl/TGraphicControl`? In that case, the grid will always be on top. – NGLN Jan 10 '13 at 10:14
  • Using all this blending, perhaps you'd really try to base your program on FireMonkey (FMX) library instead of VCL? – Arioch 'The Jan 10 '13 at 10:22
  • @NGLN The grid is made of TPanels and my custom control is based on a TPanel aswell. – Teun Pronk Jan 10 '13 at 10:23
  • I'd bet that tooltips might somewhere in Z-order tree have "always-on-top" flag. Use something to traverse hierarchy of Windows windows. Like WinSight, Spy++ (personalyl i use TotalCommander with Process MAnager plugin). Read VCL how `TCustomForm.FormStyle = fsStayOnTop` is implemented. See also [WS_EX_TOPMOST](http://msdn.microsoft.com/en-us/library/windows/desktop/ff700543.aspx) – Arioch 'The Jan 10 '13 at 10:25

1 Answers1

3
procedure TMyPanel.CreateParams(var params: TCreateParams);
begin
  params.ExStyle := params.ExStyle or WS_EX_TRANSPARENT or WS_EX_TOPMOST ;
  inherited CreateParams(params);    
end;

With a Quickhackcode I get this result

enter image description here

Just as example, Image1 contains a Semitransparent png:

unit Unit4;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, dxGDIPlusClasses;

type

  TMyPanel=Class(TPanel)
     procedure CreateParams(var params: TCreateParams); override;
     procedure WMEraseBkGnd(var msg: TWMEraseBkGnd); message WM_ERASEBKGND;
  End;


  TForm4 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    Image1: TImage;
    Button2: TButton;
    CheckBox1: TCheckBox;
    Panel2: TPanel;
    Button3: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private-Deklarationen }

   Fmp:TMyPanel;
   fisInPaint:Boolean;
  public
    { Public-Deklarationen }
  end;

var
  Form4: TForm4;

implementation

{$R *.dfm}

{ TMyPanel }

procedure TMyPanel.CreateParams(var params: TCreateParams);
begin
  params.ExStyle := params.ExStyle or WS_EX_TRANSPARENT or WS_EX_TOPMOST ;
  inherited CreateParams(params);
end;



procedure TMyPanel.WMEraseBkGnd(var msg: TWMEraseBkGnd);
begin
  SetBkMode (msg.DC, TRANSPARENT);
  msg.result := 1;
end;

procedure TForm4.Button1Click(Sender: TObject);
begin

  Fmp := TMyPanel.Create(self);
  With Fmp do
    begin
      Parent := self;
      left:= Panel1.Left -100;
      top:= Panel1.top -100;
      width := 300;
      Height := 300;
    end;
   image1.Parent := Fmp;
   Image1.Align := alClient;
   Image1.Stretch := true;
   Fmp.BringToFront;
   Label1.Parent := FMP;
   label1.Transparent := true;
   Label1.Left := 100;
   Label1.Left := 100;
end;

procedure TForm4.Button3Click(Sender: TObject);
begin
   Fmp.Left := fmp.Left + 10;
end;

end.

Can't reproduce problem with XP either:

enter image description here

bummi
  • 27,123
  • 14
  • 62
  • 101
  • Well this sort of did the trick. It will be on top now but I lost my transparency – Teun Pronk Jan 10 '13 at 10:54
  • Its weird because in the design view it shows transparent but during runtime it doesnt – Teun Pronk Jan 10 '13 at 11:01
  • Probably different Windows windows Z-order tree or maybe different flags along the way (check that), or maybe different XP MAINFESTs in Delphi exe and your exe. – Arioch 'The Jan 10 '13 at 11:32
  • And what exactly should I look for? When I wanted to do this I never thought it would be this deep lol. So to be honest right now I have no idea what i'm looking for – Teun Pronk Jan 10 '13 at 12:15
  • Well the problem is fixed now although I did it in a way that is probably the worst and nastiest way ever! I noticed I didnt have the problem if the tooltip had the same parent as the talents. however I would be limited to just that dark gray block. So I now have 2 tooltips of which one has the same parent as the talents giving that tooltip the same position as the first one makes it that you only see the part that is hidden for the other one. sort of overlap I guess. – Teun Pronk Jan 10 '13 at 14:30
  • Will accept this as the answer though since I got a lot further with your advice to begin with :) – Teun Pronk Jan 10 '13 at 14:30