Solved

A transparent form on the Desktop

Posted on 2010-08-26
4
705 Views
Last Modified: 2013-11-23
Hi,

I'm building a calendar and it needs to stay on desktop.
My form needs to be transparent and to stay maximized when the user press Show Desktop button or Win+D.
I'm using Delphi.
Windows XP, Vista and 7.

1) In order to make the form transparent, I'm using the following code:

  if SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED) = 0
  then ShowMessage(SysErrorMessage(GetLastError));


2) In order to make the form stay on desktop even when user press Win+D:

procedure TForm1.FormCreate(Sender: TObject);
var hWindow: hwnd;
begin
  hWindow := FindWindow(nil,PChar('Program Manager'));
  if hWindow <> 0 then Form1.ParentWindow := hWindow;
end;


The problem is when I set the form to stay on desktop using the code #2 the code #1 doesn't work, i.e. the form can't appear transparent.

These two code pieces work fine when tested separately.
My question is: Is there any way to put these two codes to work togheter?

Thanks
Unit1.pas
0
Comment
Question by:danival_lucas
  • 2
4 Comments
 
LVL 10

Expert Comment

by:atul_parmar
ID: 33539171
Hi, try the following.

procedure TForm1.FormCreate(Sender: TObject);
var
  hWindow: hwnd;
begin
  //make it transparent first;
  AlphaBlend := True;
  AlphaBlendValue := 100; //0 = 100% transparent, 255 = opaque
  //
  hWindow := FindWindow(nil,PChar('Program Manager'));
  if hWindow <> 0 then Windows.SetParent(Handle, hWindow);
end;
0
 
LVL 13

Accepted Solution

by:
aflarin earned 500 total points
ID: 33539424
When you the code #2, you make your form as child of 'Program Manager' window

I am afraid you can't make your form transparent then. Here is from MSDN:

WS_EX_LAYERED
Creates a layered window. Note that this cannot be used for child windows.  


0
 

Author Comment

by:danival_lucas
ID: 33544611
aflarin,
Thanks for your comment. This was very usefull to me. Now I'll start trying another options.

atul_parmar,
Your code worked in my test on Windows XP, but doesn't worked on Windows Vista (default theme) neither on Windows 7 (aero theme).
In these cases the window dissapear and only come back visible again when I choose Windows 7 Basic Theme or Windows Classic (on Vista).
Do you have any ideias why the window is not showed on these "more modern" themes?

Thank you!!!
0
 

Author Closing Comment

by:danival_lucas
ID: 33780824
Didn't solve the problem but gave directions to follow.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now