About Store Forum Documentation Contact



Post Reply 
HWND Transparency
Author Message
TBJokers Offline
Member

Post: #1
HWND Transparency
Hi, i'm trying to hide everything except my GUI in an Application. So what i did was to use D.clear(BLACK); to get easily caught pixels.

And then i added this into my Draw loop after D.clear(BLACK),

HWND hwnd = GetActiveWindow();
SetWindowLong (hwnd, GWL_EXSTYLE,
GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(hwnd, RGB(0,0,0), 0, LWA_COLORKEY);

Then after this i draw my GUI. However the Black does not disappear.
To try we've got a correct hwnd i used.

SetLayeredWindowAttributes(hwnd,0,150,LWA_ALPHA);
Then you will see the whole window getting alpha.

Does anyone here have experience with not drawing certain pixels? As i find D.clear(TRANSPARENT) only making the screen black.

Man, it's always that semicolon...
(This post was last modified: 02-07-2013 07:55 PM by TBJokers.)
02-07-2013 07:54 PM
Visit this user's website Find all posts by this user Quote this message in a reply
TBJokers Offline
Member

Post: #2
RE: HWND Transparency
The code below i use in my clean Win32 Application to run white pixels invisible and leave the rest. However when adding Esenthel's Lib this does not turn out as expected. However it does still delete all pixels at the first frame, but then the window get's it's content back but is unclickable.
Code:
#include <windows.h>
LONG winst = GetWindowLong(hWnd, GWL_STYLE);
        winst &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
SetWindowLong(hWnd, GWL_STYLE, winst);
LONG winexst = GetWindowLong(hWnd, GWL_EXSTYLE);
         winexst &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE);
SetWindowLong(hWnd, GWL_EXSTYLE, winexst);
SetWindowPos(hWnd, NULL, 0,0,0,0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
SetWindowLong (hWnd, GWL_EXSTYLE,
GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(hWnd, RGB(255,255,255), 0, LWA_COLORKEY);

Esenthel you wouldn't know what i am doing wrong?

Man, it's always that semicolon...
02-08-2013 06:08 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: HWND Transparency
I'm not sure it can work with DirectX

I've read it can work with OpenGL if the context would be initialized differently http://www.rsdn.ru/article/opengl/layeredopengl.xml

Investigating if similar thing is possible for DirectX would require lot of time.

(also thanks for sample code, I've integrated the "LWA_ALPHA" to the engine for next SDK)
02-12-2013 02:06 PM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #4
RE: HWND Transparency
http://www.codeproject.com/Articles/2852...o-D3DImage

The main concept being WPF.

another thing some people use is rendering the backbuffer and parse it into the Win32 Window, and using LWA Color to make the image transparent.

I personally wouldn't mind a OpenGL for Windows as an option either. pfft
02-12-2013 06:11 PM
Find all posts by this user Quote this message in a reply
Fex Offline
Gold Supporter

Post: #5
RE: HWND Transparency
I'm not sure if this is what your are trying to do, but I do a "blind effect" by drawing a rectangle with different alpha levels under the rest of the GUI.

Put this before you draw the rest of your GUI:
Code:
// blindness from summon or respec
      Flt alpha;
      Rect rect; rect.setC(0, 0, D.w()*2, D.h()*2);
      if(Time.realTime()-spawntime < 4.0){alpha= 1.0;} else{alpha = Pow(255, -(Time.realTime()-(spawntime+4.0))*0.09 );}
      //CM.New(S+alpha+" "+ -(Time.realTime()-spawntime));
      if(alpha > 0.01 &&  spawntime != 0.0)rect.draw(Color(0, 0, 0, 255*alpha));

put this where ever you want:
Code:
Flt spawntime = 0.0;

Now in your game you set:
Code:
spawntime = Time.realTime(); // for flash effect
whenever you want the screen to go black for ~5 seconds, the length of time and falloff can be changed in the code above as well.

*EDIT* Ok I just reread your original post, you are trying to make the area transparent down to the desktop, not black...I don't know how to do that.
(This post was last modified: 02-12-2013 07:03 PM by Fex.)
02-12-2013 07:00 PM
Find all posts by this user Quote this message in a reply
TBJokers Offline
Member

Post: #6
RE: HWND Transparency
Thank you for your time Esenthel, but I have decided to use a separate Win32 application.

Man, it's always that semicolon...
02-13-2013 09:51 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply