views:

2493

answers:

10

I'm almost certain I know the answer to this question, but I'm hoping there's something I've overlooked.

Certain applications seem to have the Vista Aero look and feel to their caption bars and buttons even when running on Windows XP. (Google Chrome and Windows Live Photo Gallery come to mind as examples.) I know that one way to accomplish this from WinForms would be to create a borderless form and draw the caption bar/buttons yourself, then overriding WndProc to make sure moving, resizing, and button clicks do what they're supposed to do (I'm not clear on the specifics but could probably pull it off given a day to read documentation.) I'm curious if there's a different, easier way that I'm overlooking. Perhaps some API calls or window styles I've overlooked?

I believe Google has answered it for me by using the roll-your-own-window approach with Chrome. I will leave the question open for another day in case someone has new information, but I believe I have answered the question myself.

A: 

Nope, I am afraid, there is no other easy way of doing this.

You are on the right track. You will need to create a custom Winform and then proceed as illustrated in this example.

Pascal
A: 

Yes. There are simle way, but it'll cost you money. All large custom control vendors have nice wrappers around WM_NCPAINT and company.

Artem Tikhomirov
A: 

Google Chrome uses the Windows Vista SDK to get the glass look on XP. You can download it here:

http://www.microsoft.com/downloads/details.aspx?FamilyID=4377f86d-c913-4b5c-b87e-ef72e5b4e065&displaylang=en

Using this, you need to enabled delay loading of the following DLL's to get the Glass Effect in XP:

  • uxtheme.dll
  • dwmapi.dl
FlySwat
This is false. See my post from Sep 4; Google Chrome uses a technique like the one @Chris Pietschmann pointed out.
OwenP
+1  A: 

@Jonathan Holland: Is this something that can be done from .NET?

OwenP
+2  A: 

@Jonathan Holland: Is this something that can be done from .NET?

Yes, using DllImport. Here is a good blog post:

http://blogs.msdn.com/tims/archive/2006/04/18/578637.aspx

FlySwat
Real neat how a comment that later turns out to be completely unrelated to the answer gets voted fairly high. This isn't an answer to my question.
OwenP
A: 

Hmmm... the blog article produces a Vista-only application, and it's only working because on Vista the window has glass by default.=. I'm going to have to unanswer the question for now. In the meantime, I'm going to dig through the Chromium source to see if it's reasonable.

OwenP
+4  A: 

Google Chrome is not using the Vista SDK to achieve this on XP. If you peek into src\chrome\browser\views\frame there are several files to define the browser frame depending on the capabilities of the system. On XP, it looks like OpaqueFrame is used; line 19 has this to say:

// OpaqueFrame
//
//  OpaqueFrame is a CustomFrameWindow subclass that in conjunction with
//  OpaqueNonClientView provides the window frame on Windows XP and on Windows
//  Vista when DWM desktop compositing is disabled. The window title and
//  borders are provided with bitmaps.

It looks like it's using the resources in src\chrome\app\theme to draw the frame buttons.

So it looks like my hopes that there's some kind of cheap way to enable Vista theming on XP are dashed. The only way to do it is to manually draw the non-client area of your window. I believe something like this is probably the right track, since it lets Windows handle the non-client stuff like moving and resizing the window.

Unless someone can find a method to magically enable the Vista theming on XP, this is the answer to the question but I obviously cannot mark my own post as the answer.

OwenP
+4  A: 

Owen, I'm using Chrome on XP and I don't see "Vista Aero" glass theme on the Chrome window. I see it as solid blue.

If it's custom theming of controls and windows title bars you want, that can be accomplished. There's an excellent, free UI toolkit for WinForms that does exactly that: KryptonToolkit

Judah Himango
A: 

I decided not to close it because I can't figure out why it would be a good idea to close it. If someone happens to know a quick trick then I'd love to know it, and closing the question denies them this chance.

@Judah Himango: It's not really glass on XP, but it has the same look without the transparency. Take a look at some of the chrome screenshots and you'll see what I mean. Instead of the traditional square buttons with the big red close button, it's a compact set of rectangular buttons that look like part of the frame. It basically looks like Aero without the class.

I was aware there's a few third-party toolkits to do this, but I was more interested in learning how it was done than finding something I could purchase to do it for me. It looks like the solution isn't trivial, but it can be done. I was mainly curious if there was something quick and easy, sort of like how EnableVisualStyles enables themed controls in .NET 2.0.

OwenP
Owen, I use Chrome, I know what you're talking about. The KryptonToolkit will work for you. You can use reflector to see how they do custom window chrome and achieve the same thing as Google Chrome.
Judah Himango
+6  A: 

Here's an article with full code sample on how to use your own custom "chrome" for an application:

http://geekswithblogs.net/kobush/articles/CustomBorderForms3.aspx

This looks like some really good stuff. There are a total of 3 articles in it's series, and it runs great, and on Vista too!

Chris Pietschmann
I had found this blog myself a while back, but forgot to add it to this question. This is the closest to an answer this question can really have without a full-fledged source sample, and it would end up pretty large.
OwenP
The concepts explained in the first article are very good. Useful for Non-.Net developers also - http://geekswithblogs.net/kobush/articles/CustomBorderForms.aspx
goths
I have used this, and i can tell you is a good approach, but it gives problems in Vista and the programmer i think does not continue to develop it, so you can find some bugs.
netadictos