Question

My WS_EX_TRANSPARENT window does not receive WM_PAINT after the window behind it re-paints.

Asked by: rpmccormi77

Project:  SKINbedder.  Embeds other programs windows to my TWindowContainer component (CustomControl), then overlays semi-transparent PNG graphics with multiple "Hot-Spot" buttons through a TSkinLayer component(CustomControl).  (mostly used to "skin" iGuidance GPS navigation software)

Problem:  When the embedded window repaints its self, my buttons disappear.  They are not re-drawn because no WM_PAINT message gets received (even though according to MSDN, a WS_EX_TRANSPARENT window should receive a WM_PAINT whenever anything underneath it is re-drawn).  I cannot continually repaint because it ruins the semi-transparency, causes flicker, and eats CPU time.  I cannot use Rgn for a transparency effect because it wouldn't work for semi-transparency plus I want to intercept mouse clicks even on the transparent parts (no click-through).

Question:  I need a way to know when my semi-transparent buttons have been erased by the embedded window repainting its self so I can repaint my buttons.  Basically I need to 1) Intercept all WM_PAINT messages to it (although I'm not sure that would work if it is repainting due to its own internal event), 2) Assign the embedded window an OnPaint or actually a "AfterPaint" event (probably impossible), or 3) Figure out why my component doesn't always receive WM_PAINT whenever anything behind it changes (as WS_EX_TRANSPARENT controls should according to M$)

Quirk / Possible alternate solution:  If you minimize then restore my app, everything is always drawn perfectly.  I guess this is because the embedded window paints first and then I paint.  I have tried to continually repaint but also continually SendMessage(EmbeddedWindowHandle, WM_PAINT, 0, 0) first.  It didn't repaint its self over my buttons though so that did not solve the ruining semi-transparency bug as I had hoped.

Source Code:  Below is the source code to my TSkinLayer.  Any suggestions about any part of the component are welcome ;).  This and TWindowContainer are my first 2 components ever (and are based on TmodderBut which was posted here on experts-exchange for an earlier version of this same program).


[code]

unit SkinLayer;

interface

uses
//  Dialogs,
  Windows, Messages, Classes, Graphics, Controls, Forms, PNGImage;

type
  THotSpots = record
    Top: integer;
    Bottom: integer;
    Left: integer;
    Right: integer;
    OnPressDown: String;
    OnPressUp: String;
    Toggle: Boolean;
   end;

  TSkinLayer = class(TCustomControl)
   private
   protected
    FNorm, FDown: TPNGObject;
    FHotSpots: Array of THotSpots;
    procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND;
    procedure CreateParams(var Params: TCreateParams); override;
    procedure Paint; override;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
   public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure WriteHotSpot(Index: integer; Top, Bottom, Left, Right: integer; OnPressUp, OnPressDown: String);
    function ReadHotSpot(Index: integer; var Top: Integer; var Bottom: Integer; var Left: Integer; var Right: integer; var OnPressUp: String; var OnPressDown: String): Boolean;
    property Canvas;
   published
    property NormalBmp: TPNGObject read FNorm write FNorm;
    property DownBmp: TPNGObject read FDown write FDown;
    property Height default 1;
    property Width default 1;
    property Visible default False;
    property Cursor default crCross;
    property Name;
    property Anchors;
    property Left;
    property Top;
    property OnMouseDown;
    property OnMouseUp;
   end;

procedure Register;

implementation

uses
  SysUtils;

procedure Register;
 begin
  RegisterComponents('RPM', [TSkinLayer]);
 end;

//--- WMEraseBkgnd -----------------------------------------------------------\\
procedure TSkinLayer.WMEraseBkgnd(var Msg: TWMEraseBkgnd);
 begin
  Msg.Result := 1;
 end;
//--- End WMEraseBkgnd -------------------------------------------------------//

//--- CreateParams -----------------------------------------------------------\\
procedure TSkinLayer.CreateParams(var Params: TCreateParams);
 begin
  inherited CreateParams(Params);
  with Params do
   begin
    WindowClass.lpszClassName := 'TSkinLayer';
    WindowClass.hbrBackground := 0;
    WindowClass.style := WindowClass.style OR CS_HREDRAW OR CS_VREDRAW OR CS_OWNDC OR CS_SAVEBITS;
    Style := Style OR WS_CHILD OR WS_CLIPSIBLINGS AND NOT(WS_TABSTOP) AND NOT(WS_VISIBLE);
    ExStyle := ExStyle OR WS_EX_TRANSPARENT;
   end;
 end;
//--- End CreateParams -------------------------------------------------------//

//--- Create -----------------------------------------------------------------\\
constructor TSkinLayer.Create(AOwner: TComponent);
 begin
  inherited Create(AOwner);
  ControlStyle := [csCaptureMouse, csClickEvents, csFixedWidth, csFixedHeight, csReflector];
  Width := 1;
  Height := 1;
  Cursor := crCross;
  Visible := False;
  FNorm := TPNGObject.Create;
  FDown := TPNGObject.Create;
 end;
//--- End Create -------------------------------------------------------------//

//--- Destroy ----------------------------------------------------------------\\
destructor TSkinLayer.Destroy;
 begin
  FreeAndNil(FNorm);
  FreeAndNil(FDown);
  inherited Destroy;
 end;
//--- End Destroy ------------------------------------------------------------//

//--- WriteHotSpot -----------------------------------------------------------\\
procedure TSkinLayer.WriteHotSpot(Index: integer; Top, Bottom, Left, Right: integer; OnPressUp, OnPressDown: String);
 begin
  if (length(FHotSpots) < (Index + 1)) then
    SetLength(FHotSpots, Index + 1);
  FHotSpots[Index].Top := Top;
  FHotSpots[Index].Bottom := Bottom;
  FHotSpots[Index].Left := Left;
  FHotSpots[Index].Right := Right;
  FHotSpots[Index].OnPressUp := OnPressUp;
  FHotSpots[Index].OnPressDown := OnPressDown;
  FHotSpots[Index].Toggle := False;
 end;
//--- End WriteHotSpot -------------------------------------------------------//

//--- ReadHotSpot ------------------------------------------------------------\\
function TSkinLayer.ReadHotSpot(Index: integer; var Top: Integer; var Bottom: Integer; var Left: Integer; var Right: integer; var OnPressUp: String; var OnPressDown: String): Boolean;
 begin
  if Index < length(FHotSpots) then
   begin
    Top := FHotSpots[Index].Top;
    Bottom := FHotSpots[Index].Bottom;
    Left := FHotSpots[Index].Left;
    Right := FHotSpots[Index].Right;
    OnPressUp := FHotSpots[Index].OnPressUp;
    OnPressDown := FHotSpots[Index].OnPressDown;
    Result := True;
   end
  else
    Result := False;
 end;
//--- End ReadHotSpot --------------------------------------------------------//

//--- Paint ------------------------------------------------------------------\\
procedure TSkinLayer.Paint;
var
  Index: Integer;
 begin
  Parent.Update;  //Reduces re-draw errors while draging a window in front of us.

  //Draw FNorm and then overlay FDown if button is Toggled (bad method!)
  if not(FNorm.Empty) then
   begin
    FNorm.Draw(Canvas, Rect(0, 0, FNorm.Width, FNorm.Height));
    if not(FDown.Empty) then
     begin
      Index := 0;
      while (Index < length(FHotSpots)) do
       begin
        if (FHotSpots[Index].Toggle) then
          FDown.Draw(Canvas, Rect(FHotSpots[Index].Left, FHotSpots[Index].Top, FHotSpots[Index].Right, FHotSpots[Index].Bottom));
        Index := Index + 1;
       end;
     end;
   end;
 end;
//--- End Paint --------------------------------------------------------------//

//--- MouseDown --------------------------------------------------------------\\
procedure TSkinLayer.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  Index: Integer;
 begin
  Index := 0;
  while (Index < length(FHotSpots)) do
   begin
    if (X > FHotSpots[Index].Left) and (X < FHotSpots[Index].Right) and (Y > FHotSpots[Index].Top) and (Y < FHotSpots[Index].Bottom) then
     begin
      if (FHotSpots[Index].OnPressDown = '') then
       begin
        //No Down Command: Just paint FDown to HotSpot.
        if (not FDown.Empty) then
          FDown.Draw(Canvas, Rect(FHotSpots[Index].Left, FHotSpots[Index].Top, FHotSpots[Index].Right, FHotSpots[Index].Bottom));
       end
      else if not(FHotSpots[Index].Toggle) then
       begin
        //Non-Toggle or 1st-Click: Run command & paint FDown to HotSpot.
        inherited;  //Command is run in external OnMouseDown Event (assigned in MainForm on create)
        if (not FDown.Empty) then
          FDown.Draw(Canvas, Rect(FHotSpots[Index].Left, FHotSpots[Index].Top, FHotSpots[Index].Right, FHotSpots[Index].Bottom));
        //If Toggle, set flag.
        if (FHotSpots[Index].OnPressUp <> '') then
          FHotSpots[Index].Toggle := True;
       end
      else
        //Toggle-Button 2nd-Click: Do nothing, but handle next up.
        FHotSpots[Index].Toggle := False;
     end;
    Index := Index + 1;
   end;
 end;
//--- End MouseDown ----------------------------------------------------------//

//--- MouseUp ----------------------------------------------------------------\\
procedure TSkinLayer.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  Index: Integer;
 begin
  Index := 0;
  while (Index < length(FHotSpots)) do
   begin
    if (X > FHotSpots[Index].Left) and (X < FHotSpots[Index].Right) and (Y > FHotSpots[Index].Top) and (Y < FHotSpots[Index].Bottom) then
     begin
      if (FHotSpots[Index].OnPressUp = '') then
       begin
        //No Up Command: Just paint FNorm to HotSpot.
        if not(FNorm.Empty) then
          FNorm.Draw(Canvas, Rect(FHotSpots[Index].Left, FHotSpots[Index].Top, FHotSpots[Index].Right, FHotSpots[Index].Bottom));
       end
      else if not(FHotSpots[Index].Toggle) then
       begin
        //Non-Toggle or 2nd-Click: Run Command and paint FNorm to HotSpot
        inherited;  //Command is run in external OnMouseDown Event (assigned in MainForm on create)
        if not(FNorm.Empty) then
          FNorm.Draw(Canvas, Rect(FHotSpots[Index].Left, FHotSpots[Index].Top, FHotSpots[Index].Right, FHotSpots[Index].Bottom));
       end;
        //If 1st-Click on Toggle-Button, do nothing.
     end;
    Index := Index + 1;
   end;
 end;
//--- End MouseUp ------------------------------------------------------------//

end.

[/code]

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-09-16 at 02:45:28ID21563691
Tags

ws_ex_transparent

Topic

Delphi Programming

Participating Experts
2
Points
250
Comments
9

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. 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.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. WM_PAINT
    How can I get WM_PAINT to work? I was trying a little experiment that didn't quite work... can anyone shed any light? void CExpDlg::OnOK() { HDC mydc = ::GetDC(this->m_hWnd); ::LineTo(mydc,100,100); HWND hw = ::FindWindow(NULL,"My Computer"); if(hw == NU...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: Slick812Posted on 2005-09-23 at 07:51:45ID: 14944736

hello rpmccormi77, ,  I am mostly commenting here because no one else has posted anything, I do not have a direct fix for your problem. . .
You say -
" a WS_EX_TRANSPARENT window should receive a WM_PAINT whenever anything underneath it is re-drawn "
I do not think this is correct, and I have used windows with the WS_EX_TRANSPARENT style, what the system seems to do is call for the Painting of windows below (Z-Order), ,  Before, it calls the Painting of the WS_EX_TRANSPARENT window, WHEN there is an area invalidation that has the WS_EX_TRANSPARENT window in it, as this will institute the WM_PAINT messages. . . I do not think  MS indicates that any refreshing of windows below the WS_EX_TRANSPARENT window, will call the WM_PAINT for the WS_EX_TRANSPARENT window, only WM_PAINT is sent if the area is invalidated?

anyway, you might try a Timer, with a 500 msecond event, and call the API functions -

InvalidateRect( )

or

RedrawWindow( )

to get a continuous updating of the area of the WS_EX_TRANSPARENT window, but this does not seem very efficient to me. .

you could also maybe, after your WS_EX_TRANSPARENT window's WM_PAINT, get a small bitmap of the area where your button (or buttons) is, and then , on a timer event, get another bitmap of that same area, and do a scanline compare of the bitmaps, if the bitmaps are not equal (no button image), then call InavalidateRect( ),, , ,
however there may be other problem will both of these methods. .  you may need to limit these timer events to just when your app has the keboard focus (top window, forground window)

 

by: rpmccormi77Posted on 2005-09-23 at 12:15:38ID: 14947447

Thanks for the reply.  I currently do use a 250ms timer to continually refresh the buttons.  This has 2 problems (besides just not being a good thing to do):  1) When the back window updates, the buttons dissapear for 0 - 250ms  2) My buttons are alpha-transparent, so repainting them (without first repainting the behind window) causes the alpha-transparancy to fade up to compleatly opaque.

Here is my current timer loop.  Most is commented out.  I have tried a ton more things than this to in order to try and solve the #2 problem.  Everything I try results in constant blinking of things.

    for Index := 1 to (length(WindowArray) - 1) do
     begin
//      WindowArray[Index].Invalidate;
//      WindowArray[Index].BringToFront;
//      WindowArray[Index].SetFocus;
      with WindowArray[Index] do
       begin
//        Windows.RedrawWindow(EmbeddedWindowHandle, 0, 0, RDW_ERASE OR RDW_INVALIDATE);
//        Windows.SetWindowPos(EmbeddedWindowHandle, HWND_TOP, 0, 0, 0, 0, SWP_DEFERERASE OR SWP_NOMOVE OR SWP_NOSIZE OR SWP_SHOWWINDOW);
       end;
     end;

    for Index := 0 to (length(SkinArray) - 1) do
     begin
      {r := Rect(SkinArray[Index].Left, SkinArray[Index].Top, SkinArray[Index].Left + SkinArray[Index].Width, SkinArray[Index].Top + SkinArray[Index].Height);
      for Index2 := 0 to (length(WindowArray) - 1) do
        Windows.RedrawWindow(WindowArray[Index2].EmbeddedWindowHandle, @r, 0, RDW_INVALIDATE OR RDW_UPDATENOW);}
      Windows.RedrawWindow(SkinArray[Index].Handle, 0, 0, RDW_INVALIDATE OR RDW_UPDATENOW);
     end;
//RDW_ERASE OR RDW_INVALIDATE OR RDW_FRAME OR RDW_ALLCHILDREN


I need some whay to tell when a behind window redraws so I can instantly update the buttons and I don't have to update the buttons when it hasn't redrawn.  Also, as a second problem with this same program...  if I make another apps window WS_EX_LAYERED using SetLong, the window never gets updated by the app.  Like I can embed a sub-window list and then move its highlight bar up and down with the arrow keys, but if I make it alpha blended (WS_EX_LAYERED), then I cannot see the highlight bar move (although if I press enter, it will choose the one as if the highlight did move...  it's just like the window wont repaint itself).  I can not get this to work even using UpdateWindow, Invalidate, and anything else I could think of.  Any clue on that one?

 

by: Slick812Posted on 2005-09-26 at 11:32:19ID: 14961325

???
I have used the method of setting my form window to "Layered" with the -
     SetWindowLong(Form1.Handle, GWL_EXSTYLE, WS_EX_LAYERED);

but if you do this (in a windows system that recognizes the WS_EX_LAYERED), I really think that the Window (Form) that now has that ex style, will HAVE to call the SetLayeredWindowAttributes( ) function, inorder for the window to paint correctly, If you have a Layered window, you must define how it is layered, , I do not remember so well , but I do not think there is a default layered specification. . .

I my form's code I have -
  SetLayeredWindowAttributes(Handle, Color, 164, LWA_ALPHA or LWA_COLORKEY);

which allows the form to be painted with the "Layered" look. . .

as for the transparent window thing, I do not beleive I would try to use a transparent window (WS_EX_TRANSPARENT) that paints anything "not solid" (blended) on it's self, I would think I would have many problems with that, as you seem to be having. . . you may try another method. . . But I am not sure if you insist on having a "Blended" , semi-transparent overlay on a window that your code does NOT control, then, you may have to do some eneficient or difficult code to get that to sort of work? ? But I really have no ways to do that, sorry

 

by: rpmccormi77Posted on 2006-05-10 at 17:27:47ID: 16654330

What?  Forced accept?  That did not work.  I still have not solved my problem.  I want my points back ;)

 

by: rpmccormi77Posted on 2006-05-11 at 01:05:59ID: 16656093

Ok, I didn't usderstand that "the question will be close" meant that my points would be given away to a non-answer (even though I did see that was the "recomendation").

To any member reading this, if you know how to help me, please post and I will award you points in a new thread or something.

 

by: cwwkiePosted on 2006-05-11 at 11:45:39ID: 16661533

rpmccormi77,

Next time if something is not clear, just ask. I am happy to help you.

If you had said this before, I think I would have changed my recommendation into Delete. That's why there is a 4 day period. I am a human too, I can make mistakes too. If you objected, I would have reread the question, and discussed about it.

But don't expect any expert to read this question after it has been open for 7 months. If you still need to solve it, you should open a new question. And if you don't get an answer within two weeks, ask for a delete/refund.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...