Solved

A transparent form on the Desktop

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Safearray problem c++ 4 88
maven import project error 7 136
Add jar to project library in intellij idea 3 378
eclipse error 7 105
In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

839 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