Solved

A transparent form on the Desktop

Posted on 2010-08-26
4
723 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
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.

730 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