Thread: Transparent Window without using Layers

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    Transparent Window without using Layers

    I want to make my window transparent without using the windows layering system. The reason for this is that I am using Managed DirectX to render stuff to a form and when I use layers to make my window semi-transparent the part being drawn by directx isn't semi-transparent and glitchy. My thought on how to manualy make this semi-transparent would be to somehow get the pixels/image behind the window and manualy blend using that.

    If anyone has any advice on how I could do this that'd be great. If anyone happens to have code I don't care what language it is. Thanks a lot!


    Edit: I have posted this at the XNA Creators Club Directx forum as well in hope to get more insight on this problem: http://forums.xna.com/45259/ShowThread.aspx
    Last edited by Rune Hunter; 02-10-2008 at 01:04 AM.

  2. #2
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    I did some more reasearch and came across a method in the Graphics object in .net called CopyFromScreen. I'm not sure if it is possible, and from the looks of it it isn't, to use that method to capture everything underneath my window and simply have Managed DirectX blend with that image to create a transparent effect.

    Only problem now is making this method or similar method copy everything underneath my window and not my window. Any thoughts?

  3. #3
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    Good idea tring not to use layers, mainly because they don't work! (see this post on 2 Window Problems). I have not found anything that changes window opacity without using layers. They are all for bitmaps. I doupt its possible.
    when I use layers to make my window semi-transparent
    This sound like layers work for you, it could just be the compiler (lcc Win32). Also what language are you using? If it is C then tell me what compiler you are using preferably not Dev-C++ (it can't find any of the functions declared in windows.h). Thx.
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Alright I think this image will better explain what I'm taking about. I guess that windows layers work for me but at the same time they don't. I am using C# and .net 2.0 but I am looking forward to a lot of interoping. I can set the opacity of the window using .net and I can aslo set it using windows layers and interoping but both produce the results in the image attached.

    The problem I have currently with using layers is that the title bar and border of the window are semi-transparent like there suposed to be, no problems there. However the inside of the form is being rendered using Managed DirectX and as you can see in the picture it is completely opaque. Not what I want at all. There is also a weird flicker on the DirectX part caused by windows layers.

    What I'm thinking for a fix would be to let windows layers do the form border and title bar and for me to manualy do the inside of the form using a bitmap of behind the window and blending it inside of DirectX. Or if the flicker still gets me I could manualy draw the entire form inside of DirectX like the first idea, though not my idea of fun.

    I have found a decent way to get the bitmap of whats behind my window using what I mentioned in my second post, however the draw back is that if a window changes behind mine I will have to somehow update my bitmap of what is behind my window. I'm not sure how I would do that.

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    It appears that everything works great if the window is partialy off the screen! Refer to the picture attatched. It has to be completely off the screen (not just under the task bar). I have no clue why this works but I got the idea after I read something about it working on a second monitor if running dual monitors. So that's the second clue, it appears to only not work if the window is fully in the first monitor. Why, I have no idea. I'm hoping somebody can help shed the light on this, this is really weird.

  6. #6
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    See the icon of the top left of the Window? That's a .NET app, layers is the only way...which in Win32 API uses the windows 2000 api called SetLayeredWindowAttributes.
    See another tips:
    http://dn.codegear.com/article/26277
    http://msdn2.microsoft.com/en-us/library/ms997507.aspx

    So, sorry...go layered-ed
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  7. #7
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Well now that I figured out that it works if the window is partialy off the screen, I figure something else is wrong.
    Last edited by Rune Hunter; 02-10-2008 at 10:16 AM.

  8. #8
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Transparent windows are supported in the Win32 API in GDI+. In order to link with it you will have to use some import statements in your C# program.

  9. #9
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    I know there supported, I'm using them. That doesn't appear to be the problem however, the problem is with how directx works with windows. I'm attempting to create a work around but not going so good.

  10. #10
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    I can't seem to edit my posts but this problem has been resolved at the XNA Creator Clubs forum. In case anyone else ever comes across this problem I'll give a brief overview.

    Exact Problem: DirectX didn't render correctly on a window that is semi-transparent using windows layers.

    Reason: DirectX draws directly onto the screen and windows layers draws the window offscreen therefore the two did not mix.

    Solution: Have DirectX render to an offscreen buffer or something similar and copy the buffer over to system memory to present on the window. This is slower than just using DirectX to do the rendering but it works.

    Thank you all for your kind help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 06:57 PM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM