troubleshooting Question

Refresh "transparent" form

Avatar of Jaymol
Jaymol asked on
Delphi
10 Comments2 Solutions366 ViewsLast Modified:
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.
ASKER CERTIFIED SOLUTION
arnismit

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros