I'm creating a window with WS_EX_LAYERED and setting a color key to it using SetLayeredWindowAttributes(). I can verify that this color key indeed creates a transparent patch in the window by drawing a simple rect using FillRect() inside the window. This doesn't work however when I'm drawing in the window using DirectDraw. I'm creating an IDirectDrawSurface7 on the window and I'm Blt()ing some pixels to it. some of the pixels are colored with the color key, but I don't see them as transparent, they just appear in the color key.
Is there something inherent in DirectDraw surface that conflicts with layered window color keying?
When i'm setting an alpha value using SetLayeredWindowAttributes(), that seem to work fine with the DirectDraw surface and it does indeed appear translucent.
I don't know if you've seen this but this paragraph from the article posted below looks kinda like what you are looking for.
The hWnd is the window handle of a window with a WS_EX_LAYERED style flag. The dwFlags parameter can have one or both of LWA_COLORKEY and LWA_ALPHA. If a LWA_COLORKEY flag is used, the crKey parameter is the transparent color key. If a LWA_ALPHA flag is used, the bAlpha parameter is the constat source alpha value. **Only top-level windows can be layered windows.**
I think its that last sentence that is the problem here. The source is a partial of a book on google books. You can read it with some code detail examples found here:
http://books.google.com/books?id=-O92IIF1Bj4C&pg=PA720&lpg=PA720&dq=WS_EX_LAYERED+%2B+DirectDraw+color+key&source=bl&ots=SyWKE3aimb&sig=DXbshrEk2tN17h7CtWdMmAkHlAo&hl=en&sa=X&ei=7_JcVKSyFMukNrumgMgB&ved=0CCkQ6AEwAg#v=onepage&q=WS_EX_LAYERED%20%2B%20DirectDraw%20color%20key&f=false
I will also include the following links that talk about a little about it, although not in nearly the same amount of detail:
http://web.cs.wpi.edu/~matt/courses/cs563/talks/cbyrd/pres3.html
http://msdn.microsoft.com/en-us/library/windows/hardware/ff567254(v=vs.85).aspx
I don't know if this will answer your question, but I hope it helps a little bit. Cheers.
Related
Capturing an image of an off-screen window with CGWindowListCreateImage is a common way to create QuickLook style zoom-in animations, but this seems create an image with the wrong background colour, slightly lighter than the real window.
This causes a flash at the end of the animation which kind of ruins the effect.
Does anyone have any idea why this happens and what can be done about it?
EDIT: I created a demonstration app for this problem. It is a bit large and complex for a Stack Overflow question, but the relevant code is probably in the ZoomingWindow.m methods takeSnapshot and makeAndPrepareSnapshotWindow.
Setting the window appearance to textured in Interface Builder fixed this. Of course that also changes the color of the window, but that is acceptable in this particular case.
While there are lots of variations of the question, there doesn't seem to be a specific answer to a simple case of wanting to use built-in common controls on a transparent window using Win32. I don't want the controls to be transparent, I just want the border around it to be transparent. I can't believe MS didn't update the .dll's to handle transparency when they added it, but I guess they forgot? Is there a specific method that works. A button can get close with WS_EX_TRANSPARENT, but flaky where it works most of the time but at times part of the border shows up. Edit controls, change depending on when get focus or not.
So the question is simply:
Is there a way to make common controls on transparent window so there is no white border around them?
If not, is there a good replacement library that does it via owner draw?
If some, which ones and what is the method?
Seems silly to reinvent the wheel just because of the area around the control.
TIA!!
If I am not mistaken, you can take the following steps to achieve this effect.
1.Create a GDI+ Bitmap object with the PixelFormat32bppPARGB pixel format.
2.Create a Graphics object to draw in this Bitmap object.
3.Do all your drawing into this object using GDI+.
4.Destroy the Graphics object created in step 2.
5.Call the GetHBITMAP method on the Bitmap object to get a Windows HBITMAP.
6.Destroy the Bitmap object.
7.Create a memory DC using CreateCompatibleDC and select the HBITMAP from step 5 into it.
8.Call UpdateLayeredWindow using the memory DC as a source.
9.Select previous bitmap and delete the memory DC.
10.Destroy the HBITMAP created in step 5.
This method should allow you to control the alpha channel of everything that is drawn: transparent for the background, opaque for the button.
A similar discussion: Transparent window containing opaque text and buttons
I made a flyout window in the notification area using WinAPI and my goal was to make it similar to the flyout windows that show up when you click some of the icons in the notification area, like the Volume icon.
I already succeeded in making it look and behave similar to the other ones, but there is one thing I can't seem to figure out. The link area of the flyout windows has a darker blueish background and there is a subtle difference in the look between Windows 7 and Windows 8. A picture of it in Windows 7 can be seen here
http://msdn.microsoft.com/en-us/library/windows/desktop/aa511448.aspx#flyouts
I achieved this by painting this link area of my flyout window manually in the right colors (including the gradient at the topmost part of the section) using the WM_PAINT message, but I just feel like it's too much of a hack, especially because it's not affected by changing themes in Windows. For example, if I set the "Windows Classic" theme this area should be grey and not blue.
So, my question is, am I missing something in how this can be achieved without painting the window manually. I noticed that the details pane in Explorer windows in Win 7 has the same look. I've searched quite a bit for answers but I haven't found anything yet. This is my first time doing a GUI using the WinAPI so I have very little experience, and therefore I'm assuming there is something that I just don't know about.
UPDATE:
I did manage to figure out how to draw this area without painting it manually. It can be drawn by using the OpenThemeData and DrawThemeBackground functions
HTHEME aeroTheme = OpenThemeData(hWnd, L"FLYOUT");
DrawThemeBackground(aeroTheme, hdc, FLYOUT_LINKAREA, 0, &rect, &rect);
This obviously only works when themes are enabled, so for non-themed cases I draw a normal rectangle with the appropriate color.
I'm not an expert in WinAPI so I can't offer any advice on achieving the look you want without manual painting.
However, if you're successfully achieving the appearance for a particular color theme, I'd suggest you look at the GetSysColor function and use this when creating your brushes for painting. This should allow you to get the correct colors based on the theme that has been set. More info (including a swatch table) can be found here.
Hope this helps.
I am trying to make a HUD with a transparent rounded window with opaque controls as is commonly seen in apps such as Xcode popups, the native volume control, etc.
I'm using the technique detailed here: How to implement HUD-style window like Address Book's "Show in Large Type"
but this renders controls in the view transparent. I've tried setAlphaValue:1.0 on the controls but that has no effect. Searches for other solutions point to Matt Gemmell's RoundedFloatingPanel component. I can't open the project in Xcode 4, but looking at the code as far as I can tell the only difference seems to be in Matt's code he sets the alpha of the window to 1.0 and uses a transparent fill for the NSRect in the view. I tried this but still end up with transparent controls.
So unsurprisingly, Matt Gemmell's code works just fine and I had made a mistake. I forgot that I was also messing with the alpha of the window elsewhere in my code in order to make it fade out on close.
To to sum it up for others running into this issue, if you set the alpha on the NSWindow the controls in that window will also be transparent. Instead set the alpha on the NSBezierPath fill color in the NSView. Just like Matt Gemmell's code does. :)
I'm trying to get the media player glass effect for an application, but I'm facing roadblocks all around. Is it me, or is it the API?
I started by calling:
MARGINS margins = { -1, -1, -1, -1 };
HRESULT result = ::DwmExtendFrameIntoClientArea(m_hWnd, &margins);
And erasing the background to black on:
OnEraseBkgnd
Everything was fine until I added an edit box. With EditBox, places where black text appears are replaced with glass. The problem is blown out of proportion with more advanced controls like ComboBoxEx and that like. Those start to look like mess.
The bright side with this approach is that the alpha blended images look alright. And are gradually blended into the glass.
The solution for edit boxes seems to be using WS_EX_LAYERED with LWA_COLORKEY and using some awful color for glass masking, and erasing the background to that color. Unfortunately this breaks other things. The alpha blending on icons looks super ugly with shadows blended to radioactive green, and the glass itself becomes click-throughable, even though I don't have a WS_EX_TRANSPARENT style on the window.
The third suggestion is sort of custom composition with GDI+, but that seems to be a bad approach, since GDI+ is a software fallback, and I can't find a way how to render EditBox or ComboBoxEx to an image that I could use for composition later.
Am I missing something?
The sources at SO also seem to face the same problems:
link1
link2
Kenny Kerr wrote an excellent article on displaying controls on glass, using edit controls as an example:
http://weblogs.asp.net/kennykerr/archive/2007/01/23/controls-and-the-desktop-window-manager.aspx
The simple answer is, you cannot do this.
All the standard controls render themselves with normal GDI calls. Normal GDI calls are alpha unaware and mostly set the alpha channel to zero.
The more complicated answer is, you can: There are some samples on the net where standard controls are mixed with aero glass. They fall into two basic categories:
WinForms (.NET) samples. WinForms don't actually use the native controls - the WinForms controls are all rewritten versions that, amongst other features, blit using alpha aware routines. This example is depressingly simple and makes me realize how much Microsoft hate native developers.
Subclassed samples: The only way to get the regular/native controls to paint on aero glass is to sublclass the controls, catch WM_PAINT messages to create a DIBBitmap, call WM_PRINT to render the controls content onto it. Use the DWM functions to repair the alpha channel data. Paint the resulting alpha'd bitap yourself using AlphaBlend.
This article on CodeProject contains a reference implementation that subclasses most of the standard controls rather well.
Try changing your text/foreground color on controls like the edit box to something "almost black" (like #010101). Then you should be able to skip the other rendering issues except alpha transparency for images/icons.
Edit: Drawing other stuff - might be some weird approaches to handle compatibility, but then again classic apps aren't glass themed by default ... don't know. Just try to avoid drawing stuff yourself, if possible.