winzip icon

Translucent window under Win9x/ME/2000

Submitted on: 1/2/2015 1:44:00 PM
By: wolf37 (from psc cd)  
Level: Intermediate
User Rating: By 7 Users
Compatibility: C, C++ (general), Microsoft Visual C++, Borland C++
Views: 441
     This is a nice example which shows you how to create a translucent window under Windows 9X/ME. Windows 2000/XP has an own function for this. Windows 98 AlphaBlending functions, but Windows 95 has nothing, so I decided to use a external function for AlphaBlending (win9x) and I used for Windows2000 the SetLayeredWindowAttributes function. The functions in gdiu.cpp were written by Graus an other programmer who works for a Programmer's Journal.

To use the code in your own applications copy the files win9Xtranslucent.cpp, win9Xtranslucent.h, win2000translucent.cpp, win2000translucent.h into your project and look at translucent.cpp, win9Xtranslucent.h, win2000translucent.h how to use the functions.

The code is not perfect! So it can be optimized. If you want to optimize the code do it like you think it's good for your project :-) For best optimitation the code must be rewritten into DirectX code.

When the application starts a copy of the desktop will be made (WM_CREATE). On the first WM_PAINT message a copy of the window will be made. The WM_PAINT message is the message where the most work is. First we calculate the size and position of the window, then we check the intersection between the backuped size, position and the new size, position. If there is a intersection we copy a section from our background backup bitmap into the new background bitmap to hide the old window. Then we copy the new position, size to the backup position, size. Now we create 2 bitmaps: the first is a copy of the window rectangle from the screen (without the window), the second is a copy of the window. This 2 bitmaps are the arguments of the AlphaBlendU function which will create a new bitmap. This bitmap will be drawn on the screen. And at last we create a new copy of the screen. The old copy is the background backup bitmap.

On WM_WINDOWPOSCHANGED message we POST a WM_PAINT message to our window for updating.

NEW: In this version the size of the window can be changed!

_____________________________ Please vote it :-)
Sorry for my bad english.

winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net

Other 4 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.