Avatar of Jaymol
Jaymol
 asked on

Refresh "transparent" form

Hi.

I wrote a component a while ago and recently found it again.  It's for making forms transparent in a manner that allows a PNG image to be placed over it and still both retain their transparency.  This is much nicer than the transparency that current windows os's offer as it's a simple on or off state for that.  This way I can place a gradiated alpha image on a form and it sits nice and smoothly over whatever's behind the form.

The problem with it is that if I bring another application over my form and then minimize it (rather than click on my form or alt-tab to it etc.) then I can still see the contents of the now minimized window.  In short - a refresh or repaint is being triggered when I bring to the application to the front, but not when it becomes the topmost through another application being minimzed.

I'd like to stop this happening.

Thanks in advance,

John.



Here's the component code.....


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

unit ClearForm;

interface

uses WinTypes, WinProcs, Messages, SysUtils, Classes, Controls,
     Forms, Graphics;

type
  TClearForm = class(TComponent)
    private
      procedure AutoInitialize;
      procedure AutoDestroy;
    protected
      procedure Loaded; override;
    public
      constructor Create(AOwner: TComponent); override;
      destructor Destroy; override;
  end;

procedure Register;

var
  MainForm      :      TForm;
  WndProc            :      Integer;
  OldWndProc      :      Integer;

implementation

procedure Register;
begin
  RegisterComponents('JCM', [TClearForm]);
end;

function HookProc(Hwnd, Msg, WParam, LParam: Integer): Integer; Stdcall;
begin
  Result:=0;
  If Msg<>WM_ERASEBKGND then
  Result:=CallWindowProc(Pointer(OldWndProc), Hwnd, Msg, WParam, LParam);
end;

procedure TClearForm.AutoInitialize;
begin
  MainForm:=TForm(Owner);
  If Not (csDesigning in ComponentState) then
  MainForm.BorderStyle:=bsNone;
  OldWndProc:=SetWindowLong(MainForm.Handle, GWL_WNDPROC, Integer(@HookProc));
end;

procedure TClearForm.AutoDestroy;
begin
end;

constructor TClearForm.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  AutoInitialize;
end;

destructor TClearForm.Destroy;
begin
  AutoDestroy;
  inherited Destroy;
end;

procedure TClearForm.Loaded;
begin
  inherited Loaded;
end;

end.
Delphi

Avatar of undefined
Last Comment
arnismit

8/22/2022 - Mon
arnismit

whatr delphi version are you using ? what OS version ??
Jaymol

ASKER
Hi.

I'm using Delphi 6 with WindowsXP, SP2.

John.
arnismit

ok, i have also delphi 6, it doesnt work in 7 at all, the program just stops running when you add your component to a form.....
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Jaymol

ASKER
Hmm...how about simply trapping the WM_ERASEBKGND message then?

Let's forget the component then - same problem, but in simple straight-forward code in the form....

Do a new application and paste this over the Form1 code.


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
  protected
        procedure WMEraseBkgnd(var Msg: TMessage); message WM_ERASEBKGND;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WMEraseBkgnd(var Msg: TMessage);
begin
      // Do nothing - just trap the event
end;

end.
arnismit

havent you noticed that the component does actually exac the same thing ?

all messages are handled in the winproc method. The component overrides that method, traps the right messag and processes the other messages normally.

Ok, this is less code, but you have to implement it everytime you want a transparent window. When you implement it in a component you just drop it on your form, and even during designing state you can see what form is transparent and which one is not.

but let me try the code in delphi 6 and see if there is the problem with the painting
Jaymol

ASKER
Erm , okay.  Yes.  I do know that it is exactly the same thing, except for the fact that the last code example does not run at component level which you said stopped Delphi 7 running.

That's why I redid the example - so that it will work in Delphi 7.

John.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
arnismit

Yes, that will be fixed by then, but it should be running in the component as well, but i dont have the time to seek that out right now.

ASKER CERTIFIED SOLUTION
arnismit

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Member_2_248744

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
arnismit

Hey John,
got it working yet ?
greetings,
arni