Solved

A transparent form on the Desktop

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

757 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

23 Experts available now in Live!

Get 1:1 Help Now